mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-10-18 06:03:22 +00:00
tests for pre-existing content retrieval
This commit is contained in:
parent
cabbe9a4bf
commit
a827d28a7b
@ -74,6 +74,15 @@ describe('Node', () => {
|
|||||||
const result = await node.once(undefined, true);
|
const result = await node.once(undefined, true);
|
||||||
expect(result).toBe(undefined);
|
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()', () => {
|
describe('node.map()', () => {
|
||||||
@ -143,6 +152,21 @@ describe('Node', () => {
|
|||||||
|
|
||||||
unsubscribe();
|
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', () => {
|
describe('Branch node behavior', () => {
|
||||||
|
@ -12,5 +12,5 @@ export type Callback = (
|
|||||||
export abstract class Adapter {
|
export abstract class Adapter {
|
||||||
abstract get(path: string, callback: Callback): Unsubscribe;
|
abstract get(path: string, callback: Callback): Unsubscribe;
|
||||||
abstract set(path: string, data: NodeValue): Promise<void>;
|
abstract set(path: string, data: NodeValue): Promise<void>;
|
||||||
// abstract list(path: string, callback: Callback): Unsubscribe; ?
|
//abstract list(path: string, callback: Callback): Unsubscribe;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import localState from '@/state/LocalState.ts';
|
|||||||
export default function useLocalState(key: string, initialValue: any = undefined, once = false) {
|
export default function useLocalState(key: string, initialValue: any = undefined, once = false) {
|
||||||
if (!initialValue) {
|
if (!initialValue) {
|
||||||
localState.get(key).once((val) => {
|
localState.get(key).once((val) => {
|
||||||
// TODO some way to get memory value
|
|
||||||
initialValue = val;
|
initialValue = val;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user