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
Changes from 1 commit
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
Next Next commit
move up singletonEntity
holic committed Aug 3, 2023
commit 6d9f166df373acfcc84278de5c24e6796ce063ce
1 change: 1 addition & 0 deletions packages/store-sync/src/recs/index.ts
Original file line number Diff line number Diff line change
@@ -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
@@ -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,
@@ -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>;
@@ -87,7 +86,7 @@ export async function syncToRecs<
...defineInternalComponents(world),
};

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

let startBlock = 0n;

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

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