From 4cdeb61f46bed511850f7fc7646bdca27f72132e Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Mon, 28 Apr 2025 23:54:22 +0300 Subject: Allow nothing to be returned by a subscription. Update README. --- src/shapex.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') 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(initialState: T): ShapeXInstance { // 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(initialState: T): ShapeXInstance { } // 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); -- cgit v1.2.3