import { shallowReactive } from '@vue/reactivity' ; import type { CommasContext } from '../types' ; const namespaces = shallowReactive < Record < string , any [ ] > > ( { } ) ; function getCollection ( name ) { if ( namespaces [ name ] ) { return namespaces [ name ] ; } namespaces [ name ] = shallowReactive ( [ ] ) ; return namespaces [ name ] ; } function cancelProviding ( name , ... data ) { const collection = getCollection ( name ) ; for ( const item of data ) { const index = collection . indexOf ( item ) ; collection . splice ( index , 1 ) ; } } function provide ( this , name , ... data ) { const collection = getCollection ( name ) ; collection . push ( ... data ) ; if ( data . length ) { this . $ . app . onCleanup ( ( ) => { cancelProviding ( name , ... data ) ; } ) ; } } export { getCollection , provide , cancelProviding , } ;