diff --git a/src/js/state/Node.test.ts b/src/js/state/Node.test.ts index a3c3b11a..10708de2 100644 --- a/src/js/state/Node.test.ts +++ b/src/js/state/Node.test.ts @@ -74,6 +74,15 @@ describe('Node', () => { const result = await node.once(undefined, true); expect(result).toBe(undefined); }); + + it('should return if the data was pre-existing in an adapter', async () => { + const adapter = new MemoryAdapter(); + const node = new Node({ id: 'user', adapters: [adapter] }); + await node.put({ name: 'Snowden', age: 30 }); + const node2 = new Node({ id: 'user', adapters: [adapter] }); + const result = await node2.once(); + expect(result).toEqual({ name: 'Snowden', age: 30 }); + }); }); describe('node.map()', () => { @@ -143,6 +152,21 @@ describe('Node', () => { unsubscribe(); }); + + it('should return if the data was pre-existing in an adapter', async () => { + const adapter = new MemoryAdapter(); + const node = new Node({ id: 'user', adapters: [adapter] }); + await node.put({ name: 'Snowden', age: 30 }); + const node2 = new Node({ id: 'user', adapters: [adapter] }); + const fn = vi.fn(); + node2.map(fn); + expect(fn).toHaveBeenCalledWith( + 'Snowden', + 'user/name', + expect.any(Number), + expect.any(Function), + ); + }); }); describe('Branch node behavior', () => { diff --git a/src/js/state/types.ts b/src/js/state/types.ts index 18ffcdf2..53b16b60 100644 --- a/src/js/state/types.ts +++ b/src/js/state/types.ts @@ -12,5 +12,5 @@ export type Callback = ( export abstract class Adapter { abstract get(path: string, callback: Callback): Unsubscribe; abstract set(path: string, data: NodeValue): Promise; - // abstract list(path: string, callback: Callback): Unsubscribe; ? + //abstract list(path: string, callback: Callback): Unsubscribe; } diff --git a/src/js/state/useLocalState.ts b/src/js/state/useLocalState.ts index b4bf3115..756d54aa 100644 --- a/src/js/state/useLocalState.ts +++ b/src/js/state/useLocalState.ts @@ -5,7 +5,6 @@ import localState from '@/state/LocalState.ts'; export default function useLocalState(key: string, initialValue: any = undefined, once = false) { if (!initialValue) { localState.get(key).once((val) => { - // TODO some way to get memory value initialValue = val; }); }