Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(store-sync): export singletonEntity as const, allow startBlock in syncToRecs #1235

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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