Skip to content

Commit

Permalink
dedupe SyncProgress
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Jan 22, 2025
1 parent f1d5432 commit 0234c16
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { defineTable } from "@latticexyz/store/internal";
import { SyncStep } from "../SyncStep";
import { getSchemaPrimitives, getValueSchema } from "@latticexyz/protocol-parser/internal";

export enum SyncStep {
INITIALIZE = "initialize",
SNAPSHOT = "snapshot",
RPC = "rpc",
LIVE = "live",
}

export const SyncProgress = defineTable({
namespaceLabel: "syncToStash",
label: "SyncProgress",
Expand Down
2 changes: 1 addition & 1 deletion packages/store-sync/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from "./common";
export * from "./configToTables";
export * from "./createStoreSync";
export * from "./SyncStep";
export * from "./SyncProgress";
export * from "./isTableRegistrationLog";
export * from "./logToTable";
export * from "./tablesWithRecordsToLogs";
Expand Down
3 changes: 3 additions & 0 deletions packages/store-sync/src/recs/createSyncAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export function createSyncAdapter<const config extends StoreConfig>({
latestBlockNumber,
lastBlockNumberProcessed,
message,
__staticData: undefined,
__encodedLengths: undefined,
__dynamicData: undefined,
});

// when we switch to live, trigger update for all entities in all components
Expand Down
26 changes: 10 additions & 16 deletions packages/store-sync/src/recs/defineInternalComponents.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { World, defineComponent, Type, Component, Schema, Metadata } from "@latticexyz/recs";
import { World } from "@latticexyz/recs";
import { tablesToComponents } from "./tablesToComponents";
import { SyncProgress } from "../SyncProgress";

export type InternalComponents = ReturnType<typeof defineInternalComponents>;
export type InternalComponents = tablesToComponents<{
SyncProgress: typeof SyncProgress;
}>;

export function defineInternalComponents(world: World) {
return {
SyncProgress: defineComponent(
world,
{
step: Type.String,
message: Type.String,
percentage: Type.Number,
latestBlockNumber: Type.BigInt,
lastBlockNumberProcessed: Type.BigInt,
},
{ metadata: { componentName: "SyncProgress" } },
),
} as const satisfies Record<string, Component<Schema, Metadata>>;
export function defineInternalComponents(world: World): InternalComponents {
return tablesToComponents(world, {
SyncProgress,
});
}
3 changes: 3 additions & 0 deletions packages/store-sync/src/recs/syncToRecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export async function syncToRecs<const config extends StoreConfig, const extraTa
latestBlockNumber,
lastBlockNumberProcessed,
message,
__staticData: undefined,
__encodedLengths: undefined,
__dynamicData: undefined,
});

// when we switch to live, trigger update for all entities in all components
Expand Down
3 changes: 1 addition & 2 deletions packages/store-sync/src/stash/createSyncAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { getRecord, setRecord, registerTable, Stash } from "@latticexyz/stash/internal";
import { createStorageAdapter } from "./createStorageAdapter";
import { SyncStep } from "../SyncStep";
import { SyncAdapter } from "../common";
import { createStoreSync } from "../createStoreSync";
import { SyncProgress } from "./common";
import { SyncProgress, SyncStep } from "../SyncProgress";

export type CreateSyncAdapterOptions = { stash: Stash };

Expand Down

0 comments on commit 0234c16

Please sign in to comment.