Add note about infinite loop

This commit is contained in:
Jim Hamill
2025-03-10 09:30:05 +00:00
parent 7cb02654b3
commit 8ad1f9d45c
4 changed files with 14 additions and 8 deletions
@@ -53,12 +53,16 @@ export class StoreComposite extends BaseStore {
for (const remoteStore of this.remoteStores) {
remoteStore.on('set', async (payload) => {
// Skip if the local store already has the key
// NOTE: It's important we DO NOT repropagate events that have already occurred.
// If we do, we can end up in infinite loops.
if (await this.localStore.has(payload.key)) return;
await this.localStore.set(payload.key, payload.value);
});
remoteStore.on('delete', async (payload) => {
// NOTE: It's important we DO NOT repropagate events that have already occurred.
// If we do, we can end up in infinite loops.
if (await this.localStore.has(payload.key)) {
await this.localStore.delete(payload.key);
}