Skip to content

Commit f4bcb78

Browse files
committed
refactor: rename tickets to collections
1 parent bd5cb4a commit f4bcb78

File tree

14 files changed

+88
-88
lines changed

14 files changed

+88
-88
lines changed

packages/0/src/composables/useGroup/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('useGroup', () => {
1515
expect(context).toHaveProperty('selectedIds')
1616
expect(context).toHaveProperty('selectedItems')
1717
expect(context).toHaveProperty('selectedValues')
18-
expect(context).toHaveProperty('tickets')
18+
expect(context).toHaveProperty('collection')
1919
})
2020

2121
it('should initialize with empty context', () => {
@@ -24,7 +24,7 @@ describe('useGroup', () => {
2424
expect(context.selectedIds.size).toBe(0)
2525
expect(context.selectedItems.value.size).toBe(0)
2626
expect(context.selectedValues.value.size).toBe(0)
27-
expect(context.tickets.size).toBe(0)
27+
expect(context.collection.size).toBe(0)
2828
})
2929
})
3030

@@ -41,7 +41,7 @@ describe('useGroup', () => {
4141
expect(ticket.index).toBe(0)
4242
expect(typeof ticket.isActive).toBe('boolean') // Ref
4343
expect(typeof ticket.toggle).toBe('function')
44-
expect(context.tickets.size).toBe(1)
44+
expect(context.collection.size).toBe(1)
4545
})
4646

4747
it('should register items with custom values', () => {
@@ -57,17 +57,17 @@ describe('useGroup', () => {
5757
expect(ticket.disabled).toBe(true)
5858
expect(ticket.value).toBe('custom-value')
5959
expect(ticket.valueIsIndex).toBe(false)
60-
expect(context.tickets.size).toBe(1)
60+
expect(context.collection.size).toBe(1)
6161
})
6262

6363
it('should unregister items', () => {
6464
const context = useGroup('test')[2]
6565

6666
context.register({ id: 'test-item' })
67-
expect(context.tickets.size).toBe(1)
67+
expect(context.collection.size).toBe(1)
6868

6969
context.unregister('test-item')
70-
expect(context.tickets.size).toBe(0)
70+
expect(context.collection.size).toBe(0)
7171
})
7272

7373
it('should remove from selectedIds when unregistering', () => {
@@ -181,7 +181,7 @@ describe('useGroup', () => {
181181
context.mandate()
182182

183183
if (context.selectedIds.size === 0) {
184-
expect(context.tickets.size).toBe(2)
184+
expect(context.collection.size).toBe(2)
185185
} else {
186186
expect(context.selectedIds.has('item1')).toBe(true)
187187
expect(context.selectedIds.size).toBe(1)

packages/0/src/composables/useGroup/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ export type GroupOptions = {
4545
}
4646

4747
/**
48-
* Creates a group registrar for managing group tickets within a specific namespace.
48+
* Creates a group registrar for managing group items within a specific namespace.
4949
* This function provides a way to register, unregister, and manage group selections,
5050
* allowing for dynamic group management in applications.
5151
*
5252
* @param namespace The namespace for the group context.
5353
* @param options Optional configuration for the group behavior.
54-
* @template Z The type of the group tickets managed by the registrar.
54+
* @template Z The type of the group items managed by the registrar.
5555
* @template E The type of the group context.
5656
* @returns A tuple containing the inject function, provide function, and the group context.
5757
*
@@ -72,7 +72,7 @@ export function useGroup<
7272

7373
const selectedItems = computed(() => {
7474
return new Set(
75-
Array.from(selectedIds).map(id => registrar.tickets.get(id)),
75+
Array.from(selectedIds).map(id => registrar.collection.get(id)),
7676
)
7777
})
7878

@@ -93,15 +93,15 @@ export function useGroup<
9393
}
9494

9595
function mandate () {
96-
if (!options?.mandatory || selectedIds.size > 0 || registrar.tickets.size === 0) return
96+
if (!options?.mandatory || selectedIds.size > 0 || registrar.collection.size === 0) return
9797

9898
if (options.mandatory === 'force') {
99-
const first = registrar.tickets.values().next().value
99+
const first = registrar.collection.values().next().value
100100
if (first) selectedIds.add(first.id)
101101
return
102102
}
103103

104-
for (const item of registrar.tickets.values()) {
104+
for (const item of registrar.collection.values()) {
105105
if (item.disabled) continue
106106
selectedIds.add(item.id)
107107

@@ -127,7 +127,7 @@ export function useGroup<
127127
for (const id of Array.isArray(ids) ? ids : [ids]) {
128128
if (!id) continue
129129

130-
const item = registrar.tickets.get(id)
130+
const item = registrar.collection.get(id)
131131

132132
if (!item || item.disabled) continue
133133

@@ -154,7 +154,7 @@ export function useGroup<
154154
function register (registrant: Partial<E>, id: ID = genId()): Reactive<E> {
155155
const item: Partial<E> = {
156156
disabled: false,
157-
value: registrant?.value ?? registrar.tickets.size,
157+
value: registrant?.value ?? registrar.collection.size,
158158
valueIsIndex: registrant?.value == null,
159159
isActive: toRef(() => selectedIds.has(ticket.id)),
160160
toggle: () => toggle(ticket.id),

packages/0/src/composables/useLocale/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('useLocale', () => {
5555
const state = createLocale('test', { adapter, messages })[2]
5656

5757
expect(state.selectedId.value).toBeUndefined()
58-
expect(state.tickets.size).toBe(0)
58+
expect(state.collection.size).toBe(0)
5959
})
6060
})
6161

packages/0/src/composables/useLocale/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface LocalePlugin {
4141
* @param namespace The namespace for the locale context.
4242
* @param options Configuration including adapter and messages.
4343
* @template Z The type of the locale context.
44-
* @template E The type of the locale tickets managed by the registrar.
44+
* @template E The type of the locale items managed by the registrar.
4545
* @returns An array containing the inject function, provide function, and the locale context.
4646
*/
4747
export function createLocale<
@@ -106,9 +106,9 @@ export function useLocale (): LocaleContext {
106106
*
107107
* @param options Configuration for adapter, default locale, and messages.
108108
* @template Z The type of the locale context.
109-
* @template E The type of the locale tickets managed by the registrar.
109+
* @template E The type of the locale items managed by the registrar.
110110
* @template R The type of the token context.
111-
* @template O The type of the token tickets managed by the registrar.
111+
* @template O The type of the token items managed by the registrar.
112112
* @returns Vue install function for the plugin
113113
*/
114114
export function createLocalePlugin<

packages/0/src/composables/useRegistrar/index.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ describe('useRegistrar', () => {
1111
const ticket1 = context.register({ id: 'item1' })
1212
expect(ticket1.id).toBe('item1')
1313
expect(ticket1.index).toBe(0)
14-
expect(context.tickets.size).toBe(1)
14+
expect(context.collection.size).toBe(1)
1515

1616
const ticket2 = context.register()
1717
expect(ticket2.index).toBe(1)
18-
expect(context.tickets.size).toBe(2)
18+
expect(context.collection.size).toBe(2)
1919

2020
const ticket3 = context.register({ id: 'item3' })
2121
expect(ticket3.id).toBe('item3')
2222
expect(ticket3.index).toBe(2)
23-
expect(context.tickets.size).toBe(3)
23+
expect(context.collection.size).toBe(3)
2424

2525
context.unregister('item1')
26-
expect(context.tickets.size).toBe(2)
27-
expect(context.tickets.has('item1')).toBe(false)
26+
expect(context.collection.size).toBe(2)
27+
expect(context.collection.has('item1')).toBe(false)
2828

29-
expect(context.tickets.has(ticket2.id)).toBe(true)
30-
expect(context.tickets.has('item3')).toBe(true)
29+
expect(context.collection.has(ticket2.id)).toBe(true)
30+
expect(context.collection.has('item3')).toBe(true)
3131
})
3232

3333
it('should auto-generate unique IDs', () => {
@@ -37,7 +37,7 @@ describe('useRegistrar', () => {
3737
const ticket2 = context.register()
3838

3939
expect(ticket1.id).not.toBe(ticket2.id)
40-
expect(context.tickets.size).toBe(2)
40+
expect(context.collection.size).toBe(2)
4141
})
4242

4343
it('should maintain correct indices after reindexing', () => {
@@ -56,9 +56,9 @@ describe('useRegistrar', () => {
5656
const ticket4 = context.register({ id: 'item4' })
5757
expect(ticket4.index).toBe(2)
5858

59-
expect(context.tickets.has('item1')).toBe(true)
60-
expect(context.tickets.has('item2')).toBe(false)
61-
expect(context.tickets.has('item3')).toBe(true)
62-
expect(context.tickets.has('item4')).toBe(true)
59+
expect(context.collection.has('item1')).toBe(true)
60+
expect(context.collection.has('item2')).toBe(false)
61+
expect(context.collection.has('item3')).toBe(true)
62+
expect(context.collection.has('item4')).toBe(true)
6363
})
6464
})

packages/0/src/composables/useRegistrar/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export interface RegistrarTicket {
1616
}
1717

1818
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 */
2121
lookup: (index: number) => ID | undefined
22-
/** Find a ticket by id */
22+
/** Find an item by id */
2323
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 */
2727
unregister: (id: ID) => void
2828
/** Reset the index directory and update all items */
2929
reindex: () => void
@@ -33,7 +33,7 @@ export interface RegistrarContext {
3333
* A composable for managing a collection of info.
3434
* @param namespace The key to scope the context
3535
* @template Z The registry context interface.
36-
* @template E The structure of the tickets.
36+
* @template E The structure of the collection.
3737
* @returns A trinity of registry methods.
3838
*/
3939
export function useRegistrar<
@@ -42,11 +42,11 @@ export function useRegistrar<
4242
> (namespace: string) {
4343
const [useRegistrarContext, _provideRegistrarContext] = createContext<Z>(namespace)
4444

45-
const tickets = reactive(new Map<ID, E>())
45+
const collection = reactive(new Map<ID, E>())
4646
const directory = reactive(new Map<number, ID>())
4747

4848
function find (id: ID) {
49-
return tickets.get(id) as E | undefined
49+
return collection.get(id) as E | undefined
5050
}
5151

5252
function lookup (index: number) {
@@ -56,7 +56,7 @@ export function useRegistrar<
5656
function reindex () {
5757
directory.clear()
5858
let index = 0
59-
for (const item of tickets.values()) {
59+
for (const item of collection.values()) {
6060
item.index = index
6161
directory.set(index, item.id)
6262
index++
@@ -66,29 +66,29 @@ export function useRegistrar<
6666
function register (registrant: Partial<E>, id: ID = genId()): Reactive<E> {
6767
const item = reactive({
6868
id,
69-
index: registrant?.index ?? tickets.size,
69+
index: registrant?.index ?? collection.size,
7070
...registrant,
7171
}) as Reactive<E>
7272

73-
tickets.set(item.id, item as any)
73+
collection.set(item.id, item as any)
7474
directory.set(item.index, item.id)
7575

7676
return item
7777
}
7878

7979
function unregister (id: ID) {
80-
const item = tickets.get(id)
80+
const item = collection.get(id)
8181

8282
if (!item) return
8383

8484
directory.delete(item.index)
85-
tickets.delete(item.id)
85+
collection.delete(item.id)
8686

8787
reindex()
8888
}
8989

9090
const context = {
91-
tickets,
91+
collection,
9292
lookup,
9393
find,
9494
register,

packages/0/src/composables/useSingle/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('useSingle', () => {
99
expect(state.selectedIds.size).toBe(0)
1010
expect(state.selectedItems.value.size).toBe(0)
1111
expect(state.selectedValues.value.size).toBe(0)
12-
expect(state.tickets.size).toBe(0)
12+
expect(state.collection.size).toBe(0)
1313
})
1414
})
1515

packages/0/src/composables/useSingle/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export type SingleContext = GroupContext & {
3333
*
3434
* @param namespace The namespace for the single context.
3535
* @param options Optional configuration for the single behavior.
36-
* @template Z The type of the single tickets managed by the registrar.
36+
* @template Z The type of the single items managed by the registrar.
3737
* @template E The type of the single context.
3838
* @returns A tuple containing the inject function, provide function, and the single context.
3939
*/
@@ -50,7 +50,7 @@ export function useSingle<
5050
const [useGroupContext, provideGroupContext, registrar] = useGroup<Z, E>(namespace, options)
5151

5252
const selectedId = computed(() => registrar.selectedIds.values().next().value)
53-
const selectedItem = computed(() => selectedId.value ? registrar.tickets.get(selectedId.value) : undefined)
53+
const selectedItem = computed(() => selectedId.value ? registrar.collection.get(selectedId.value) : undefined)
5454
const selectedIndex = computed(() => selectedItem.value ? selectedItem.value.index : -1)
5555
const selectedValue = computed(() => selectedItem.value ? selectedItem.value.value : undefined)
5656

packages/0/src/composables/useStep/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('useStep', () => {
99
expect(state.selectedIds.size).toBe(0)
1010
expect(state.selectedItems.value.size).toBe(0)
1111
expect(state.selectedValues.value.size).toBe(0)
12-
expect(state.tickets.size).toBe(0)
12+
expect(state.collection.size).toBe(0)
1313
expect(state.selectedItem.value).toBeUndefined()
1414
})
1515
})
@@ -28,18 +28,18 @@ describe('useStep', () => {
2828
expect(ticket.index).toBe(0)
2929
expect(typeof ticket.isActive).toBe('boolean')
3030
expect(typeof ticket.toggle).toBe('function')
31-
expect(state.tickets.size).toBe(1)
31+
expect(state.collection.size).toBe(1)
3232
})
3333

3434
it('should unregister items', () => {
3535
const [, provideStepContext, state] = useStep('test')
3636
const context = provideStepContext()
3737

3838
context.register({ id: 'test-item' })
39-
expect(state.tickets.size).toBe(1)
39+
expect(state.collection.size).toBe(1)
4040

4141
context.unregister('test-item')
42-
expect(state.tickets.size).toBe(0)
42+
expect(state.collection.size).toBe(0)
4343
})
4444
})
4545

packages/0/src/composables/useStep/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type StepContext = SingleContext & {
2424
*
2525
* @param namespace The namespace for the step context.
2626
* @param options Optional configuration for the step behavior.
27-
* @template Z The type of the step tickets managed by the registrar.
27+
* @template Z The type of the step items managed by the registrar.
2828
* @template E The type of the step context.
2929
* @returns A tuple containing the inject function, provide function, and the step context.
3030
*/
@@ -38,7 +38,7 @@ export function useStep<
3838
const [useGroupContext, provideGroupContext, registrar] = useSingle<Z, E>(namespace, options)
3939

4040
function first () {
41-
if (registrar.tickets.size === 0) return
41+
if (registrar.collection.size === 0) return
4242

4343
const firstId = registrar.lookup(0)
4444
if (firstId === undefined) return
@@ -48,9 +48,9 @@ export function useStep<
4848
}
4949

5050
function last () {
51-
if (registrar.tickets.size === 0) return
51+
if (registrar.collection.size === 0) return
5252

53-
const lastIndex = registrar.tickets.size - 1
53+
const lastIndex = registrar.collection.size - 1
5454
const lastId = registrar.lookup(lastIndex)
5555
if (lastId === undefined) return
5656

@@ -71,15 +71,15 @@ export function useStep<
7171
}
7272

7373
function step (count = 1) {
74-
const length = registrar.tickets.size
74+
const length = registrar.collection.size
7575
if (!length) return
7676

7777
const direction = Math.sign(count || 1)
7878
let hops = 0
7979
let index = wrapped(length, registrar.selectedIndex.value + count)
8080
let id = registrar.lookup(index)
8181

82-
while (id !== undefined && registrar.tickets.get(id)?.disabled && hops < length) {
82+
while (id !== undefined && registrar.collection.get(id)?.disabled && hops < length) {
8383
index = wrapped(length, index + direction)
8484
id = registrar.lookup(index)
8585
hops++

0 commit comments

Comments
 (0)