Skip to content

Commit de28e0e

Browse files
Merge pull request #313 from edisontim/feat/allow-historical-as-param
feat: allow passing historical as a parameter
2 parents 9aa8f33 + a2e0cef commit de28e0e

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

packages/state/src/recs/index.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const getSyncEntities = async <S extends Schema>(
6363
* @param entityKeyClause - An array of entity key clauses to synchronize.
6464
* @param limit - The maximum number of events to fetch per request (default: 100).
6565
* @param logging - Whether to log debug information (default: false).
66+
* @param historical - Whether to fetch and subscribe to historical events (default: true).
6667
* @returns A promise that resolves to a subscription for event updates.
6768
*
6869
* @example
@@ -89,11 +90,18 @@ export const getSyncEvents = async <S extends Schema>(
8990
clause: Clause | undefined,
9091
entityKeyClause: EntityKeysClause[],
9192
limit: number = 100,
92-
logging: boolean = false
93+
logging: boolean = false,
94+
historical: boolean = true
9395
) => {
9496
if (logging) console.log("Starting getSyncEvents");
95-
await getEvents(client, components, limit, clause, logging);
96-
return await syncEvents(client, components, entityKeyClause, logging);
97+
await getEvents(client, components, limit, clause, logging, historical);
98+
return await syncEvents(
99+
client,
100+
components,
101+
entityKeyClause,
102+
logging,
103+
historical
104+
);
97105
};
98106

99107
/**
@@ -150,13 +158,15 @@ export const getEntities = async <S extends Schema>(
150158
* @param limit - The maximum number of event messages to fetch per request (default: 100).
151159
* @param clause - An optional clause to filter event messages.
152160
* @param logging - Whether to log debug information (default: false).
161+
* @param historical - Whether to fetch historical events (default: true).
153162
*/
154163
export const getEvents = async <S extends Schema>(
155164
client: ToriiClient,
156165
components: Component<S, Metadata, undefined>[],
157166
limit: number = 100,
158167
clause: Clause | undefined,
159-
logging: boolean = false
168+
logging: boolean = false,
169+
historical: boolean = true
160170
) => {
161171
if (logging) console.log("Starting getEvents");
162172
let offset = 0;
@@ -170,7 +180,7 @@ export const getEvents = async <S extends Schema>(
170180
clause,
171181
dont_include_hashed_keys: false,
172182
},
173-
true
183+
historical
174184
);
175185

176186
if (logging) console.log("entities", entities);
@@ -291,6 +301,7 @@ export const syncEntities = async <S extends Schema>(
291301
* @param components - An array of component definitions.
292302
* @param entityKeyClause - An array of EntityKeysClause to filter entities.
293303
* @param logging - Whether to log debug information (default: false).
304+
* @param historical - Whether to sync to historical events (default: true).
294305
* @returns A promise that resolves with the subscription handler.
295306
* @example
296307
* const sync = await syncEvents(client, components, entityKeyClause);
@@ -301,12 +312,13 @@ export const syncEvents = async <S extends Schema>(
301312
client: ToriiClient,
302313
components: Component<S, Metadata, undefined>[],
303314
entityKeyClause: EntityKeysClause[],
304-
logging: boolean = false
315+
logging: boolean = false,
316+
historical: boolean = true
305317
) => {
306318
if (logging) console.log("Starting syncEvents");
307319
return await client.onEventMessageUpdated(
308320
entityKeyClause,
309-
true,
321+
historical,
310322
(fetchedEntities: any, data: any) => {
311323
if (logging) console.log("Event message updated", fetchedEntities);
312324

0 commit comments

Comments
 (0)