summaryrefslogtreecommitdiff
path: root/src/shapex.ts
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2025-04-28 23:54:22 +0300
committerAsko Nõmm <asko@nmm.ee>2025-04-28 23:54:22 +0300
commit4cdeb61f46bed511850f7fc7646bdca27f72132e (patch)
tree1242d37833b750925c6ee544d42fcc8886e4306f /src/shapex.ts
parentb08c553749f6619815c171175dd6bcf8ee6ab035 (diff)
Allow nothing to be returned by a subscription. Update README.
Diffstat (limited to 'src/shapex.ts')
-rw-r--r--src/shapex.ts8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/shapex.ts b/src/shapex.ts
index 1bd4b17..4fde18b 100644
--- a/src/shapex.ts
+++ b/src/shapex.ts
@@ -254,7 +254,7 @@ export function ShapeX<T extends object>(initialState: T): ShapeXInstance<T> {
// Updates state, and checks for state changes, and if any changes present,
// fires a dispatch for all the state listeners (if there are any).
- if (typeof response.state !== "undefined") {
+ if (response?.state !== undefined) {
const changes = changedState(_state, response.state);
_state = response.state;
@@ -264,17 +264,17 @@ export function ShapeX<T extends object>(initialState: T): ShapeXInstance<T> {
}
// Dispatches events
- if (response.dispatch) {
+ if (response?.dispatch !== undefined) {
if (isSubscriptionResponseList(response.dispatch)) {
for (const dispatchee of response.dispatch) {
- if (dispatchee.with) {
+ if (dispatchee?.with) {
dispatch(dispatchee.to, dispatchee.with);
} else {
dispatch(dispatchee.to);
}
}
} else {
- if (response.dispatch.with) {
+ if (response.dispatch?.with) {
dispatch(response.dispatch.to, response.dispatch.with);
} else {
dispatch(response.dispatch.to);