From d0f65c5a51681ef1c45120b54f3cee557568004a Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 1 Sep 2022 13:56:21 +1000 Subject: [PATCH] =?UTF-8?q?feature:=20skip=20render=20this=20will=20allow?= =?UTF-8?q?=20user=20to=20update=20the=20store=20without=E2=80=A6=20(#134)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feature: skip render this will allow user to update the store without trigger the context update * 4.6.0-next.0 * fix type error * 4.6.0-next.1 --- package.json | 2 +- src/stateMachine.tsx | 4 ++-- src/types.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 430d7b4..ec01529 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "files": [ "dist" ], - "version": "4.5.0", + "version": "4.6.0-next.1", "main": "dist/little-state-machine.js", "module": "dist/little-state-machine.es.js", "unpkg": "dist/little-state-machine.umd.js", diff --git a/src/stateMachine.tsx b/src/stateMachine.tsx index a3fa2a7..b83b176 100644 --- a/src/stateMachine.tsx +++ b/src/stateMachine.tsx @@ -37,7 +37,7 @@ const actionTemplate = setState: React.Dispatch>, callback: TCallback, ) => - (payload: Parameters[1]) => { + (payload: Parameters[1], options?: { skipRender: boolean }) => { if (process.env.NODE_ENV !== 'production') { window[STORE_ACTION_NAME] = callback.name; } @@ -52,7 +52,7 @@ const actionTemplate = ); } - setState(storeFactory.state); + (!options || !options.skipRender) && setState(storeFactory.state); storeFactory.options.persist !== PERSIST_BEFORE_UNLOAD && storeFactory.saveStore(); }; diff --git a/src/types.ts b/src/types.ts index dbd88b1..b2e83cc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -10,7 +10,7 @@ export type ActionsOutput< TCallback extends AnyCallback, TActions extends AnyActions, > = { - [K in keyof TActions]: (payload?: Parameters[1]) => void; + [K in keyof TActions]: (payload?: Parameters[1], options?: { skipRender: boolean }) => void; }; export type StateMachineContextValue = {