@@ -16,14 +16,14 @@ export interface RegistrarTicket {
16
16
}
17
17
18
18
export interface RegistrarContext {
19
- tickets : Reactive < Map < ID , Reactive < any > > >
20
- /** lookup a ticket by index number */
19
+ collection : Reactive < Map < ID , Reactive < any > > >
20
+ /** lookup an item by index number */
21
21
lookup : ( index : number ) => ID | undefined
22
- /** Find a ticket by id */
22
+ /** Find an item by id */
23
23
find : ( id : ID ) => Reactive < any > | undefined
24
- /** Register a new ticket */
25
- register : ( ticket ?: Partial < RegistrarTicket > , id ?: ID ) => Reactive < any >
26
- /** Unregister a ticket by id */
24
+ /** Register a new item */
25
+ register : ( item ?: Partial < RegistrarTicket > , id ?: ID ) => Reactive < any >
26
+ /** Unregister an item by id */
27
27
unregister : ( id : ID ) => void
28
28
/** Reset the index directory and update all items */
29
29
reindex : ( ) => void
@@ -33,7 +33,7 @@ export interface RegistrarContext {
33
33
* A composable for managing a collection of info.
34
34
* @param namespace The key to scope the context
35
35
* @template Z The registry context interface.
36
- * @template E The structure of the tickets .
36
+ * @template E The structure of the collection .
37
37
* @returns A trinity of registry methods.
38
38
*/
39
39
export function useRegistrar <
@@ -42,11 +42,11 @@ export function useRegistrar<
42
42
> ( namespace : string ) {
43
43
const [ useRegistrarContext , _provideRegistrarContext ] = createContext < Z > ( namespace )
44
44
45
- const tickets = reactive ( new Map < ID , E > ( ) )
45
+ const collection = reactive ( new Map < ID , E > ( ) )
46
46
const directory = reactive ( new Map < number , ID > ( ) )
47
47
48
48
function find ( id : ID ) {
49
- return tickets . get ( id ) as E | undefined
49
+ return collection . get ( id ) as E | undefined
50
50
}
51
51
52
52
function lookup ( index : number ) {
@@ -56,7 +56,7 @@ export function useRegistrar<
56
56
function reindex ( ) {
57
57
directory . clear ( )
58
58
let index = 0
59
- for ( const item of tickets . values ( ) ) {
59
+ for ( const item of collection . values ( ) ) {
60
60
item . index = index
61
61
directory . set ( index , item . id )
62
62
index ++
@@ -66,29 +66,29 @@ export function useRegistrar<
66
66
function register ( registrant : Partial < E > , id : ID = genId ( ) ) : Reactive < E > {
67
67
const item = reactive ( {
68
68
id,
69
- index : registrant ?. index ?? tickets . size ,
69
+ index : registrant ?. index ?? collection . size ,
70
70
...registrant ,
71
71
} ) as Reactive < E >
72
72
73
- tickets . set ( item . id , item as any )
73
+ collection . set ( item . id , item as any )
74
74
directory . set ( item . index , item . id )
75
75
76
76
return item
77
77
}
78
78
79
79
function unregister ( id : ID ) {
80
- const item = tickets . get ( id )
80
+ const item = collection . get ( id )
81
81
82
82
if ( ! item ) return
83
83
84
84
directory . delete ( item . index )
85
- tickets . delete ( item . id )
85
+ collection . delete ( item . id )
86
86
87
87
reindex ( )
88
88
}
89
89
90
90
const context = {
91
- tickets ,
91
+ collection ,
92
92
lookup,
93
93
find,
94
94
register,
0 commit comments