Skip to content

Commit

Permalink
wip - rollback returning values in actions (not allowed w/ immer)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyfrc committed Jul 17, 2024
1 parent ac8c231 commit 9767c80
Show file tree
Hide file tree
Showing 6 changed files with 12,756 additions and 63 deletions.
4,273 changes: 4,256 additions & 17 deletions build/cami.cdn.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/cami.cdn.js.map

Large diffs are not rendered by default.

4,252 changes: 4,235 additions & 17 deletions build/cami.module.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/cami.module.js.map

Large diffs are not rendered by default.

4,274 changes: 4,256 additions & 18 deletions docs/javascripts/cami.cdn.js

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions src/observables/observable-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,13 @@ class ObservableStore extends Observable {

if (!reducer) {
console.warn(`No reducer found for action ${action}`);
return;
return _deepClone(this._state);
}

this.__applyMiddleware(action, payload);

let actionResult;
const [nextState, patches, inversePatches] = produceWithPatches(this._state, draft => {
actionResult = reducer({
reducer({
state: draft,
payload: payload,
dispatch: this.dispatch.bind(this),
Expand All @@ -282,7 +281,6 @@ class ObservableStore extends Observable {
memo: this.memo.bind(this),
trigger: this.trigger.bind(this)
});
return actionResult === undefined ? draft : actionResult;
});

try {
Expand Down Expand Up @@ -320,7 +318,7 @@ class ObservableStore extends Observable {
}
}

return actionResult !== undefined ? actionResult : _deepClone(this._state);
return _deepClone(this._state);
} finally {
this.__dispatchStack.pop();
this.__isDispatching = false;
Expand Down

0 comments on commit 9767c80

Please sign in to comment.