diff --git a/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/composables.ts b/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/composables.ts index 576ecb8..9def914 100644 --- a/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/composables.ts +++ b/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/composables.ts @@ -1,7 +1,20 @@ -import type { UseCheckpointFunction as UseCheckpointFunctionWithSchemas } from './with-schemas/composables.js' -import type { UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas } from './without-schemas/composables.js' +import type { + UseCheckpointFunction as UseCheckpointFunctionWithSchemas, + UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithSchemas, +} from './with-schemas/composables.js' +import type { + UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas, + UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithoutSchemas, +} from './without-schemas/composables.js' export type UseCheckpointFunction = UseCheckpointFunctionWithSchemas & UseCheckpointFunctionWithoutSchemas +export type UseCheckpointIdsFunction = UseCheckpointIdsFunctionWithSchemas & UseCheckpointIdsFunctionWithoutSchemas -export type { UseCheckpointFunction as UseCheckpointFunctionWithSchemas } from './with-schemas/composables.js' -export type { UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas } from './without-schemas/composables.js' +export type { + UseCheckpointFunction as UseCheckpointFunctionWithSchemas, + UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithSchemas, +} from './with-schemas/composables.js' +export type { + UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas, + UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithoutSchemas, +} from './without-schemas/composables.js' diff --git a/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/with-schemas/composables.ts b/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/with-schemas/composables.ts index 145e7e6..ab31dcd 100644 --- a/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/with-schemas/composables.ts +++ b/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/with-schemas/composables.ts @@ -1,7 +1,9 @@ import type { ComputedRef, MaybeRefOrGetter } from '@vue/reactivity' -import type { Checkpoints, Id } from 'tinybase/with-schemas' +import type { Checkpoints, Id, CheckpointIds } from 'tinybase/with-schemas' export type UseCheckpointFunction = ( checkpoints: Checkpoints, checkpointId: MaybeRefOrGetter, ) => ComputedRef + +export type UseCheckpointIdsFunction = (checkpoints: Checkpoints) => ComputedRef diff --git a/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/without-schemas/composables.ts b/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/without-schemas/composables.ts index a554c4d..0ab3c4f 100644 --- a/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/without-schemas/composables.ts +++ b/packages/public/vue-tinybase/src/@types/custom-store/checkpoints/without-schemas/composables.ts @@ -1,7 +1,9 @@ import type { ComputedRef, MaybeRefOrGetter } from '@vue/reactivity' -import type { Checkpoints, Id } from 'tinybase' +import type { CheckpointIds, Checkpoints, Id } from 'tinybase' export type UseCheckpointFunction = ( checkpoints: Checkpoints, checkpointId: MaybeRefOrGetter, ) => ComputedRef + +export type UseCheckpointIdsFunction = (checkpoints: Checkpoints) => ComputedRef diff --git a/packages/public/vue-tinybase/src/@types/default-store/checkpoints/composables.ts b/packages/public/vue-tinybase/src/@types/default-store/checkpoints/composables.ts index 576ecb8..9def914 100644 --- a/packages/public/vue-tinybase/src/@types/default-store/checkpoints/composables.ts +++ b/packages/public/vue-tinybase/src/@types/default-store/checkpoints/composables.ts @@ -1,7 +1,20 @@ -import type { UseCheckpointFunction as UseCheckpointFunctionWithSchemas } from './with-schemas/composables.js' -import type { UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas } from './without-schemas/composables.js' +import type { + UseCheckpointFunction as UseCheckpointFunctionWithSchemas, + UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithSchemas, +} from './with-schemas/composables.js' +import type { + UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas, + UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithoutSchemas, +} from './without-schemas/composables.js' export type UseCheckpointFunction = UseCheckpointFunctionWithSchemas & UseCheckpointFunctionWithoutSchemas +export type UseCheckpointIdsFunction = UseCheckpointIdsFunctionWithSchemas & UseCheckpointIdsFunctionWithoutSchemas -export type { UseCheckpointFunction as UseCheckpointFunctionWithSchemas } from './with-schemas/composables.js' -export type { UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas } from './without-schemas/composables.js' +export type { + UseCheckpointFunction as UseCheckpointFunctionWithSchemas, + UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithSchemas, +} from './with-schemas/composables.js' +export type { + UseCheckpointFunction as UseCheckpointFunctionWithoutSchemas, + UseCheckpointIdsFunction as UseCheckpointIdsFunctionWithoutSchemas, +} from './without-schemas/composables.js' diff --git a/packages/public/vue-tinybase/src/@types/default-store/checkpoints/with-schemas/composables.ts b/packages/public/vue-tinybase/src/@types/default-store/checkpoints/with-schemas/composables.ts index b18b1ec..d9d9516 100644 --- a/packages/public/vue-tinybase/src/@types/default-store/checkpoints/with-schemas/composables.ts +++ b/packages/public/vue-tinybase/src/@types/default-store/checkpoints/with-schemas/composables.ts @@ -1,4 +1,6 @@ import type { ComputedRef, MaybeRefOrGetter } from '@vue/reactivity' -import type { Id } from 'tinybase/with-schemas' +import type { Id, CheckpointIds } from 'tinybase/with-schemas' export type UseCheckpointFunction = (checkpointId: MaybeRefOrGetter) => ComputedRef + +export type UseCheckpointIdsFunction = () => ComputedRef diff --git a/packages/public/vue-tinybase/src/@types/default-store/checkpoints/without-schemas/composables.ts b/packages/public/vue-tinybase/src/@types/default-store/checkpoints/without-schemas/composables.ts index 3cd0024..534d147 100644 --- a/packages/public/vue-tinybase/src/@types/default-store/checkpoints/without-schemas/composables.ts +++ b/packages/public/vue-tinybase/src/@types/default-store/checkpoints/without-schemas/composables.ts @@ -1,4 +1,6 @@ import type { ComputedRef, MaybeRefOrGetter } from '@vue/reactivity' -import type { Id } from 'tinybase' +import type { Id, CheckpointIds } from 'tinybase' export type UseCheckpointFunction = (checkpointId: MaybeRefOrGetter) => ComputedRef + +export type UseCheckpointIdsFunction = () => ComputedRef diff --git a/packages/public/vue-tinybase/src/custom-store/checkpoints/composables.test.ts b/packages/public/vue-tinybase/src/custom-store/checkpoints/composables.test.ts index 9f796ae..a8be652 100644 --- a/packages/public/vue-tinybase/src/custom-store/checkpoints/composables.test.ts +++ b/packages/public/vue-tinybase/src/custom-store/checkpoints/composables.test.ts @@ -3,7 +3,7 @@ import { createStore, createCheckpoints } from 'tinybase' import { expect, test } from 'vitest' import { defineComponent, h, nextTick } from 'vue' -import { useCheckpoint } from './composables.js' +import { useCheckpoint, useCheckpointIds } from './composables.js' test('[custom-store/checkpoints/composables] useCheckpoint', async () => { const store = createStore() @@ -27,3 +27,26 @@ test('[custom-store/checkpoints/composables] useCheckpoint', async () => { expect(wrapper.text()).toBe('sale') }) + +test('[custom-store/checkpoints/composables] useCheckpointIds', async () => { + const store = createStore() + const checkpoints = createCheckpoints(store) + + const Component = defineComponent({ + setup() { + const checkpoint = useCheckpointIds(checkpoints) + + return () => h('div', [JSON.stringify(checkpoint.value)]) + }, + }) + + const wrapper = mount(Component) + expect(wrapper.text()).toBe('[[],"0",[]]') + + store.setCell('pets', 'fido', 'sold', true) + checkpoints.addCheckpoint('sale') + + await nextTick() + + expect(wrapper.text()).toBe('[["0"],"1",[]]') +}) diff --git a/packages/public/vue-tinybase/src/custom-store/checkpoints/composables.ts b/packages/public/vue-tinybase/src/custom-store/checkpoints/composables.ts index fefd630..8caf3fe 100644 --- a/packages/public/vue-tinybase/src/custom-store/checkpoints/composables.ts +++ b/packages/public/vue-tinybase/src/custom-store/checkpoints/composables.ts @@ -1,8 +1,11 @@ import { ReturnType, useListenable } from '../../common/useListenable.js' -import type { UseCheckpointFunction } from '../../@types/custom-store/index.js' +import type { UseCheckpointFunction, UseCheckpointIdsFunction } from '../../@types/custom-store/index.js' import type { MaybeRefOrGetter } from '@vue/reactivity' import type { Checkpoints, Id } from 'tinybase' export const useCheckpoint = ((checkpoints: Checkpoints, checkpointId: MaybeRefOrGetter) => useListenable(checkpoints, 'Checkpoint', ReturnType.CellOrValue, [checkpointId])) as UseCheckpointFunction + +export const useCheckpointIds = ((checkpoints: Checkpoints) => + useListenable(checkpoints, 'CheckpointIds', ReturnType.Checkpoints)) as UseCheckpointIdsFunction diff --git a/packages/public/vue-tinybase/src/default-store/checkpoints/composables.test.ts b/packages/public/vue-tinybase/src/default-store/checkpoints/composables.test.ts index ec0610e..166fff7 100644 --- a/packages/public/vue-tinybase/src/default-store/checkpoints/composables.test.ts +++ b/packages/public/vue-tinybase/src/default-store/checkpoints/composables.test.ts @@ -5,7 +5,7 @@ import { defineComponent, h, nextTick } from 'vue' import { providerWrapper } from '../../test-utils/store.js' -import { useCheckpoint } from './composables.js' +import { useCheckpoint, useCheckpointIds } from './composables.js' test('[default-store/checkpoints/composables] useCheckpoint', async () => { const store = createStore() @@ -29,3 +29,26 @@ test('[default-store/checkpoints/composables] useCheckpoint', async () => { expect(wrapper.text()).toBe('sale') }) + +test('[default-store/checkpoints/composables] useCheckpointIds', async () => { + const store = createStore() + const checkpoints = createCheckpoints(store) + + const Component = defineComponent({ + setup() { + const checkpoint = useCheckpointIds() + + return () => h('div', [JSON.stringify(checkpoint.value)]) + }, + }) + + const wrapper = mount(providerWrapper(Component, undefined, { checkpoints })) + expect(wrapper.text()).toBe('[[],"0",[]]') + + store.setCell('pets', 'fido', 'sold', true) + checkpoints.addCheckpoint('sale') + + await nextTick() + + expect(wrapper.text()).toBe('[["0"],"1",[]]') +}) diff --git a/packages/public/vue-tinybase/src/default-store/checkpoints/composables.ts b/packages/public/vue-tinybase/src/default-store/checkpoints/composables.ts index e73e8f0..5107750 100644 --- a/packages/public/vue-tinybase/src/default-store/checkpoints/composables.ts +++ b/packages/public/vue-tinybase/src/default-store/checkpoints/composables.ts @@ -2,9 +2,12 @@ import { ReturnType, useListenable } from '../../common/useListenable.js' import { injectCheckpoints } from './context.js' -import type { UseCheckpointFunction } from '../../@types/default-store/index.js' +import type { UseCheckpointFunction, UseCheckpointIdsFunction } from '../../@types/default-store/index.js' import type { MaybeRefOrGetter } from '@vue/reactivity' import type { Id } from 'tinybase' export const useCheckpoint = ((checkpointId: MaybeRefOrGetter) => useListenable(injectCheckpoints(), 'Checkpoint', ReturnType.CellOrValue, [checkpointId])) as UseCheckpointFunction + +export const useCheckpointIds = (() => + useListenable(injectCheckpoints(), 'CheckpointIds', ReturnType.Checkpoints)) as UseCheckpointIdsFunction