Skip to content

Commit

Permalink
feat: 🧑‍💻 setSubscriptions will only accept functions and will dele…
Browse files Browse the repository at this point in the history
…te non-function params
  • Loading branch information
CourtHive committed Mar 29, 2024
1 parent f1e7125 commit 27753c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/examples/asyncEngine/asyncGlobalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ function setSubscriptions(params) {
const instanceState = getInstanceState();

Object.keys(params.subscriptions).forEach((subscription) => {
instanceState.subscriptions[subscription] = params.subscriptions[subscription];
if (typeof params.subscriptions[subscription] === 'function') {
instanceState.subscriptions[subscription] = params.subscriptions[subscription];
} else {
delete instanceState.subscriptions[subscription];
}
});
return { ...SUCCESS };
}
Expand Down
4 changes: 4 additions & 0 deletions src/global/state/globalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ export function getTopics() {
return _globalStateProvider.getTopics();
}

export function hasTopic(topic) {
return getTopics()?.topics?.includes(topic);
}

export type CallListenerArgs = {
notices: Notice[];
topic: string;
Expand Down
6 changes: 5 additions & 1 deletion src/global/state/syncGlobalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ export function setSubscriptions(params: any) {
if (typeof params.subscriptions !== 'object') return { error: INVALID_VALUES };

Object.keys(params.subscriptions).forEach((subscription) => {
syncGlobalState.subscriptions[subscription] = params.subscriptions[subscription];
if (typeof params.subscriptions[subscription] === 'function') {
syncGlobalState.subscriptions[subscription] = params.subscriptions[subscription];
} else {
delete syncGlobalState.subscriptions[subscription];
}
});

return { ...SUCCESS };
Expand Down
6 changes: 5 additions & 1 deletion src/server/providers/factory/engines/asyncGlobalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ function setSubscriptions(params) {
const instanceState = getInstanceState();

Object.keys(params.subscriptions).forEach((subscription) => {
instanceState.subscriptions[subscription] = params.subscriptions[subscription];
if (typeof params.subscriptions[subscription] === 'function') {
instanceState.subscriptions[subscription] = params.subscriptions[subscription];
} else {
delete instanceState.subscriptions[subscription];
}
});
return { ...SUCCESS };
}
Expand Down

0 comments on commit 27753c1

Please sign in to comment.