Share server store without Persister? #174
Unanswered
waynesbrain
asked this question in
Q&A
Replies: 1 comment
-
For now I just created import type {
MergeableStore,
PersistedContent,
Persister,
Persists,
PersisterListener,
Store,
OptionalSchemas,
} from "tinybase/with-schemas";
import { createCustomPersister } from "tinybase/with-schemas";
type PContent<Schemas extends OptionalSchemas> = PersistedContent<
Schemas,
Persists.StoreOrMergeableStore
>;
type PListener<Schemas extends OptionalSchemas> = PersisterListener<
Schemas,
Persists.StoreOrMergeableStore
>;
export interface MemoryPersister<Schemas extends OptionalSchemas>
extends Persister<Schemas, Persists.StoreOrMergeableStore> {}
export function createMemoryPersister<Schemas extends OptionalSchemas>(
store: Store<Schemas> | MergeableStore<Schemas>,
onIgnoredError?: (error: any) => void,
): MemoryPersister<Schemas> {
let state: PContent<Schemas> | undefined = undefined;
async function getPersisted(): Promise<PContent<Schemas> | undefined> {
console.log("MEM GET");
return state;
}
async function setPersisted(
getContent: () => PContent<Schemas>,
): Promise<void> {
console.log("MEM SET");
state = getContent();
}
function addPersisterListener(listener: PListener<Schemas>): string {
console.log("MEM LISTEN");
return "subscription";
}
function delPersisterListener(subscription: string): void {
console.log("MEM HANGUP");
}
return createCustomPersister(
store,
getPersisted,
setPersisted,
addPersisterListener,
delPersisterListener,
onIgnoredError,
3, // Persists.StoreOrMergeableStore,
) as MemoryPersister<Schemas>;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Can I create a store in a server package and share it to clients over websockets but without creating a perister?
Beta Was this translation helpful? Give feedback.
All reactions