UNPKG

@dojoengine/sdk

Version:

Dojo SDK: Build onchain and provable apps faster

40 lines (37 loc) 1.87 kB
import { StoreApi } from 'zustand'; import { S as SchemaType, P as ParsedEntity } from './types-DbGeload.js'; import { Patch, Draft } from 'immer'; import '@dojoengine/torii-wasm/types'; import 'neverthrow'; import 'starknet'; import '@dojoengine/torii-wasm'; interface PendingTransaction { transactionId: string; patches: Patch[]; inversePatches: Patch[]; } interface GameState<T extends SchemaType> { entities: Record<string, ParsedEntity<T>>; pendingTransactions: Record<string, PendingTransaction>; setEntities: (entities: ParsedEntity<T>[]) => void; mergeEntities: (entities: ParsedEntity<T>[]) => void; updateEntity: (entity: Partial<ParsedEntity<T>>) => void; applyOptimisticUpdate: (transactionId: string, updateFn: (draft: Draft<GameState<T>>) => void) => void; revertOptimisticUpdate: (transactionId: string) => void; confirmTransaction: (transactionId: string) => void; subscribeToEntity: (entityId: string, listener: (entity: ParsedEntity<T> | undefined) => void) => () => void; waitForEntityChange: (entityId: string, predicate: (entity: ParsedEntity<T> | undefined) => boolean, timeout?: number) => Promise<ParsedEntity<T> | undefined>; getEntity: (entityId: string) => ParsedEntity<T> | undefined; getEntities: (filter?: (entity: ParsedEntity<T>) => boolean) => ParsedEntity<T>[]; getEntitiesByModel: (namespace: keyof T, model: keyof T[keyof T]) => ParsedEntity<T>[]; resetStore: () => void; } type DojoStore<T extends SchemaType> = StoreApi<GameState<T>>; /** * Factory function to create a Vanilla Zustand store based on a given SchemaType. * * @template T - The schema type. * @returns A Zustand hook tailored to the provided schema. */ declare function createDojoStore<T extends SchemaType>(): StoreApi<GameState<T>>; export { type DojoStore, type GameState, createDojoStore };