Skip to content

Commit

Permalink
feat(store-sync): export singletonEntity as const, allow startBlock i…
Browse files Browse the repository at this point in the history
…n syncToRecs (#1235)
  • Loading branch information
holic authored Aug 3, 2023
1 parent c1d2249 commit 582388b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
15 changes: 15 additions & 0 deletions .changeset/metal-cats-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@latticexyz/store-sync": patch
---

Add `startBlock` option to `syncToRecs`.

```ts
import { syncToRecs } from "@latticexyz/store-sync/recs";
import worlds from "contracts/worlds.json";

syncToRecs({
startBlock: worlds['31337'].blockNumber,
...
});
```
11 changes: 11 additions & 0 deletions .changeset/nice-moose-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@latticexyz/store-sync": minor
---

Export `singletonEntity` as const rather than within the `syncToRecs` result.

```diff
- const { singletonEntity, ... } = syncToRecs({ ... });
+ import { singletonEntity, syncToRecs } from "@latticexyz/store-sync/recs";
+ const { ... } = syncToRecs({ ... });
```
1 change: 1 addition & 0 deletions packages/store-sync/src/recs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from "./encodeEntity";
export * from "./entityToHexKeyTuple";
export * from "./hexKeyTupleToEntity";
export * from "./recsStorage";
export * from "./singletonEntity";
export * from "./syncToRecs";
3 changes: 3 additions & 0 deletions packages/store-sync/src/recs/singletonEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { hexKeyTupleToEntity } from "./hexKeyTupleToEntity";

export const singletonEntity = hexKeyTupleToEntity([]);
6 changes: 2 additions & 4 deletions packages/store-sync/src/recs/syncToRecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import {
import { filter, map, tap, mergeMap, from, concatMap, Observable, share, firstValueFrom } from "rxjs";
import { BlockStorageOperations, blockLogsToStorage } from "../blockLogsToStorage";
import { recsStorage } from "./recsStorage";
import { hexKeyTupleToEntity } from "./hexKeyTupleToEntity";
import { debug } from "./debug";
import { defineInternalComponents } from "./defineInternalComponents";
import { getTableKey } from "./getTableKey";
import { StoreComponentMetadata, SyncStep } from "./common";
import { encodeEntity } from "./encodeEntity";
import { createIndexerClient } from "../trpc-indexer";
import { singletonEntity } from "./singletonEntity";

type SyncToRecsOptions<
TConfig extends StoreConfig = StoreConfig,
Expand Down Expand Up @@ -58,7 +58,6 @@ type SyncToRecsResult<
> = {
// TODO: return publicClient?
components: TComponents & ReturnType<typeof defineInternalComponents>;
singletonEntity: Entity;
latestBlock$: Observable<Block>;
latestBlockNumber$: Observable<bigint>;
blockLogs$: Observable<BlockLogs>;
Expand Down Expand Up @@ -87,7 +86,7 @@ export async function syncToRecs<
...defineInternalComponents(world),
};

const singletonEntity = world.registerEntity({ id: hexKeyTupleToEntity([]) });
world.registerEntity({ id: singletonEntity });

let startBlock = 0n;

Expand Down Expand Up @@ -238,7 +237,6 @@ export async function syncToRecs<

return {
components,
singletonEntity,
latestBlock$,
latestBlockNumber$,
blockLogs$,
Expand Down

0 comments on commit 582388b

Please sign in to comment.