From f765ef920b8a84bf68e36ed9a7910c5027fd63bd Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Tue, 2 Aug 2022 20:00:20 +0100 Subject: [PATCH] 0.2.8 --- packages/liquorstore/CHANGELOG.md | 6 ++++ packages/liquorstore/package.json | 2 +- packages/liquorstore/src/lib/LiquorStore.ts | 39 +++++++++------------ 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/packages/liquorstore/CHANGELOG.md b/packages/liquorstore/CHANGELOG.md index 3e434e0..a5c3bba 100644 --- a/packages/liquorstore/CHANGELOG.md +++ b/packages/liquorstore/CHANGELOG.md @@ -1,5 +1,11 @@ # trashly-react +## 0.2.8 + +### Patch Changes + +- Fix returns on undo / redo + ## 0.2.7 ### Patch Changes diff --git a/packages/liquorstore/package.json b/packages/liquorstore/package.json index b52b0d5..991cc6f 100644 --- a/packages/liquorstore/package.json +++ b/packages/liquorstore/package.json @@ -1,6 +1,6 @@ { "name": "liquorstore", - "version": "0.2.7", + "version": "0.2.8", "description": "A reactive store for React.", "license": "MIT", "author": { diff --git a/packages/liquorstore/src/lib/LiquorStore.ts b/packages/liquorstore/src/lib/LiquorStore.ts index 2edd876..fc2241f 100644 --- a/packages/liquorstore/src/lib/LiquorStore.ts +++ b/packages/liquorstore/src/lib/LiquorStore.ts @@ -181,6 +181,7 @@ export class LiquorStore> extends EventEmitter { this.willChange() this.current = next this.didChange(patch) + return this } /** @@ -193,17 +194,11 @@ export class LiquorStore> extends EventEmitter { */ update = (fn: (state: T) => void) => { this.willChange() - const tNext = Object.assign({}, this.current) - fn(tNext) - this.current = this.processState(tNext) - const patch = diff(this.prev, this.current) - this.didChange(patch) - return this } @@ -261,16 +256,16 @@ export class LiquorStore> extends EventEmitter { this.isPaused = false } - if (!this.canUndo) return + if (this.canUndo) { + const patch = this.history[this.pointer] - const patch = this.history[this.pointer] - - this.pointer-- - this.prev = this.current - this.current = this.applyPatch(patch, true) + this.pointer-- + this.prev = this.current + this.current = this.applyPatch(patch, true) - this.emit("undo") - this.notifySubscriptions(patch) + this.emit("undo") + this.notifySubscriptions(patch) + } return this } @@ -294,17 +289,17 @@ export class LiquorStore> extends EventEmitter { this.isPaused = false } - if (!this.canRedo) return - - this.pointer++ + if (this.canRedo) { + this.pointer++ - const patch = this.history[this.pointer] + const patch = this.history[this.pointer] - this.prev = this.current - this.current = this.applyPatch(patch) + this.prev = this.current + this.current = this.applyPatch(patch) - this.emit("redo") - this.notifySubscriptions(patch) + this.emit("redo") + this.notifySubscriptions(patch) + } return this }