Skip to content

Commit 856497d

Browse files
committed
feat: allow callback function after getEvents
1 parent b47c945 commit 856497d

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

packages/state/src/recs/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const getSyncEntities = async <S extends Schema>(
6464
* @param limit - The maximum number of events to fetch per request (default: 100).
6565
* @param logging - Whether to log debug information (default: false).
6666
* @param historical - Whether to fetch and subscribe to historical events (default: false).
67+
* @param callback - An optional callback function to be called after fetching events.
6768
* @returns A promise that resolves to a subscription for event updates.
6869
*
6970
* @example
@@ -91,17 +92,20 @@ export const getSyncEvents = async <S extends Schema>(
9192
entityKeyClause: EntityKeysClause[],
9293
limit: number = 100,
9394
logging: boolean = false,
94-
historical: boolean = true
95+
historical: boolean = true,
96+
callback?: () => void
9597
) => {
9698
if (logging) console.log("Starting getSyncEvents");
97-
await getEvents(client, components, limit, clause, logging, historical);
98-
return await syncEvents(
99+
await getEvents(
99100
client,
100101
components,
101-
entityKeyClause,
102+
limit,
103+
clause,
102104
logging,
103-
historical
105+
historical,
106+
callback
104107
);
108+
return await syncEvents(client, components, entityKeyClause, logging);
105109
};
106110

107111
/**
@@ -159,14 +163,16 @@ export const getEntities = async <S extends Schema>(
159163
* @param clause - An optional clause to filter event messages.
160164
* @param logging - Whether to log debug information (default: false).
161165
* @param historical - Whether to fetch historical events (default: false).
166+
* @param callback - An optional callback function to be called after fetching events.
162167
*/
163168
export const getEvents = async <S extends Schema>(
164169
client: ToriiClient,
165170
components: Component<S, Metadata, undefined>[],
166171
limit: number = 100,
167172
clause: Clause | undefined,
168173
logging: boolean = false,
169-
historical: boolean = false
174+
historical: boolean = false,
175+
callback?: () => void
170176
) => {
171177
if (logging) console.log("Starting getEvents");
172178
let offset = 0;
@@ -193,6 +199,8 @@ export const getEvents = async <S extends Schema>(
193199
offset += limit;
194200
}
195201
}
202+
203+
callback && callback();
196204
};
197205

198206
/**

packages/state/src/utils/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ function handleStringArray(value: any) {
5656
try {
5757
return BigInt(a.value);
5858
} catch (error) {
59-
console.warn(
60-
`Failed to convert ${a.value} to BigInt. Using string value instead.`
61-
);
6259
return a.value;
6360
}
6461
});

0 commit comments

Comments
 (0)