Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1f11096

Browse files
committedJul 27, 2024··
feat(checkpoints): add useCheckpointIds composable
1 parent ec0ce29 commit 1f11096

File tree

10 files changed

+102
-16
lines changed

10 files changed

+102
-16
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
import type { UseCheckpointFunction as UseCheckpointFunctionWithSchemas } from './with-schemas/composables.js'
2-
import type { UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas } from './without-schemas/composables.js'
1+
import type {
2+
UseCheckpointFunction as UseCheckpointFunctionWithSchemas,
3+
UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithSchemas,
4+
} from './with-schemas/composables.js'
5+
import type {
6+
UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas,
7+
UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithoutSchemas,
8+
} from './without-schemas/composables.js'
39

410
export type UseCheckpointFunction = UseCheckpointFunctionWithSchemas & UseCheckpointFunctionWithoutSchemas
11+
export type UseCheckpointIdsFunction = UseCheckpointIdsFunctionWithSchemas & UseCheckpointIdsFunctionWithoutSchemas
512

6-
export type { UseCheckpointFunction as UseCheckpointFunctionWithSchemas } from './with-schemas/composables.js'
7-
export type { UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas } from './without-schemas/composables.js'
13+
export type {
14+
UseCheckpointFunction as UseCheckpointFunctionWithSchemas,
15+
UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithSchemas,
16+
} from './with-schemas/composables.js'
17+
export type {
18+
UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas,
19+
UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithoutSchemas,
20+
} from './without-schemas/composables.js'
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { ComputedRef, MaybeRefOrGetter } from '@vue/reactivity'
2-
import type { Checkpoints, Id } from 'tinybase/with-schemas'
2+
import type { Checkpoints, Id, CheckpointIds } from 'tinybase/with-schemas'
33

44
export type UseCheckpointFunction = (
55
checkpoints: Checkpoints<any>,
66
checkpointId: MaybeRefOrGetter<Id>,
77
) => ComputedRef<string | undefined>
8+
9+
export type UseCheckpointIdsFunction = (checkpoints: Checkpoints<any>) => ComputedRef<CheckpointIds>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { ComputedRef, MaybeRefOrGetter } from '@vue/reactivity'
2-
import type { Checkpoints, Id } from 'tinybase'
2+
import type { CheckpointIds, Checkpoints, Id } from 'tinybase'
33

44
export type UseCheckpointFunction = (
55
checkpoints: Checkpoints,
66
checkpointId: MaybeRefOrGetter<Id>,
77
) => ComputedRef<string | undefined>
8+
9+
export type UseCheckpointIdsFunction = (checkpoints: Checkpoints) => ComputedRef<CheckpointIds>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
import type { UseCheckpointFunction as UseCheckpointFunctionWithSchemas } from './with-schemas/composables.js'
2-
import type { UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas } from './without-schemas/composables.js'
1+
import type {
2+
UseCheckpointFunction as UseCheckpointFunctionWithSchemas,
3+
UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithSchemas,
4+
} from './with-schemas/composables.js'
5+
import type {
6+
UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas,
7+
UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithoutSchemas,
8+
} from './without-schemas/composables.js'
39

410
export type UseCheckpointFunction = UseCheckpointFunctionWithSchemas & UseCheckpointFunctionWithoutSchemas
11+
export type UseCheckpointIdsFunction = UseCheckpointIdsFunctionWithSchemas & UseCheckpointIdsFunctionWithoutSchemas
512

6-
export type { UseCheckpointFunction as UseCheckpointFunctionWithSchemas } from './with-schemas/composables.js'
7-
export type { UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas } from './without-schemas/composables.js'
13+
export type {
14+
UseCheckpointFunction as UseCheckpointFunctionWithSchemas,
15+
UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithSchemas,
16+
} from './with-schemas/composables.js'
17+
export type {
18+
UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas,
19+
UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithoutSchemas,
20+
} from './without-schemas/composables.js'
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { ComputedRef, MaybeRefOrGetter } from '@vue/reactivity'
2-
import type { Id } from 'tinybase/with-schemas'
2+
import type { Id, CheckpointIds } from 'tinybase/with-schemas'
33

44
export type UseCheckpointFunction = (checkpointId: MaybeRefOrGetter<Id>) => ComputedRef<string | undefined>
5+
6+
export type UseCheckpointIdsFunction = () => ComputedRef<CheckpointIds>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { ComputedRef, MaybeRefOrGetter } from '@vue/reactivity'
2-
import type { Id } from 'tinybase'
2+
import type { Id, CheckpointIds } from 'tinybase'
33

44
export type UseCheckpointFunction = (checkpointId: MaybeRefOrGetter<Id>) => ComputedRef<string | undefined>
5+
6+
export type UseCheckpointIdsFunction = () => ComputedRef<CheckpointIds>

‎packages/public/vue-tinybase/src/custom-store/checkpoints/composables.test.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createStore, createCheckpoints } from 'tinybase'
33
import { expect, test } from 'vitest'
44
import { defineComponent, h, nextTick } from 'vue'
55

6-
import { useCheckpoint } from './composables.js'
6+
import { useCheckpoint, useCheckpointIds } from './composables.js'
77

88
test('[custom-store/checkpoints/composables] useCheckpoint', async () => {
99
const store = createStore()
@@ -27,3 +27,26 @@ test('[custom-store/checkpoints/composables] useCheckpoint', async () => {
2727

2828
expect(wrapper.text()).toBe('sale')
2929
})
30+
31+
test('[custom-store/checkpoints/composables] useCheckpointIds', async () => {
32+
const store = createStore()
33+
const checkpoints = createCheckpoints(store)
34+
35+
const Component = defineComponent({
36+
setup() {
37+
const checkpoint = useCheckpointIds(checkpoints)
38+
39+
return () => h('div', [JSON.stringify(checkpoint.value)])
40+
},
41+
})
42+
43+
const wrapper = mount(Component)
44+
expect(wrapper.text()).toBe('[[],"0",[]]')
45+
46+
store.setCell('pets', 'fido', 'sold', true)
47+
checkpoints.addCheckpoint('sale')
48+
49+
await nextTick()
50+
51+
expect(wrapper.text()).toBe('[["0"],"1",[]]')
52+
})
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { ReturnType, useListenable } from '../../common/useListenable.js'
22

3-
import type { UseCheckpointFunction } from '../../@types/custom-store/index.js'
3+
import type { UseCheckpointFunction, UseCheckpointIdsFunction } from '../../@types/custom-store/index.js'
44
import type { MaybeRefOrGetter } from '@vue/reactivity'
55
import type { Checkpoints, Id } from 'tinybase'
66

77
export const useCheckpoint = ((checkpoints: Checkpoints, checkpointId: MaybeRefOrGetter<Id>) =>
88
useListenable(checkpoints, 'Checkpoint', ReturnType.CellOrValue, [checkpointId])) as UseCheckpointFunction
9+
10+
export const useCheckpointIds = ((checkpoints: Checkpoints) =>
11+
useListenable(checkpoints, 'CheckpointIds', ReturnType.Checkpoints)) as UseCheckpointIdsFunction

‎packages/public/vue-tinybase/src/default-store/checkpoints/composables.test.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { defineComponent, h, nextTick } from 'vue'
55

66
import { providerWrapper } from '../../test-utils/store.js'
77

8-
import { useCheckpoint } from './composables.js'
8+
import { useCheckpoint, useCheckpointIds } from './composables.js'
99

1010
test('[default-store/checkpoints/composables] useCheckpoint', async () => {
1111
const store = createStore()
@@ -29,3 +29,26 @@ test('[default-store/checkpoints/composables] useCheckpoint', async () => {
2929

3030
expect(wrapper.text()).toBe('sale')
3131
})
32+
33+
test('[default-store/checkpoints/composables] useCheckpointIds', async () => {
34+
const store = createStore()
35+
const checkpoints = createCheckpoints(store)
36+
37+
const Component = defineComponent({
38+
setup() {
39+
const checkpoint = useCheckpointIds()
40+
41+
return () => h('div', [JSON.stringify(checkpoint.value)])
42+
},
43+
})
44+
45+
const wrapper = mount(providerWrapper(Component, undefined, { checkpoints }))
46+
expect(wrapper.text()).toBe('[[],"0",[]]')
47+
48+
store.setCell('pets', 'fido', 'sold', true)
49+
checkpoints.addCheckpoint('sale')
50+
51+
await nextTick()
52+
53+
expect(wrapper.text()).toBe('[["0"],"1",[]]')
54+
})

‎packages/public/vue-tinybase/src/default-store/checkpoints/composables.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import { ReturnType, useListenable } from '../../common/useListenable.js'
22

33
import { injectCheckpoints } from './context.js'
44

5-
import type { UseCheckpointFunction } from '../../@types/default-store/index.js'
5+
import type { UseCheckpointFunction, UseCheckpointIdsFunction } from '../../@types/default-store/index.js'
66
import type { MaybeRefOrGetter } from '@vue/reactivity'
77
import type { Id } from 'tinybase'
88

99
export const useCheckpoint = ((checkpointId: MaybeRefOrGetter<Id>) =>
1010
useListenable(injectCheckpoints(), 'Checkpoint', ReturnType.CellOrValue, [checkpointId])) as UseCheckpointFunction
11+
12+
export const useCheckpointIds = (() =>
13+
useListenable(injectCheckpoints(), 'CheckpointIds', ReturnType.Checkpoints)) as UseCheckpointIdsFunction

0 commit comments

Comments
 (0)
Please sign in to comment.