Skip to content

Commit

Permalink
0.2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
steveruizok committed Aug 2, 2022
1 parent 0bfb641 commit f765ef9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
6 changes: 6 additions & 0 deletions packages/liquorstore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# trashly-react

## 0.2.8

### Patch Changes

- Fix returns on undo / redo

## 0.2.7

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/liquorstore/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "liquorstore",
"version": "0.2.7",
"version": "0.2.8",
"description": "A reactive store for React.",
"license": "MIT",
"author": {
Expand Down
39 changes: 17 additions & 22 deletions packages/liquorstore/src/lib/LiquorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export class LiquorStore<T extends Record<string, any>> extends EventEmitter {
this.willChange()
this.current = next
this.didChange(patch)
return this
}

/**
Expand All @@ -193,17 +194,11 @@ export class LiquorStore<T extends Record<string, any>> 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
}

Expand Down Expand Up @@ -261,16 +256,16 @@ export class LiquorStore<T extends Record<string, any>> 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
}
Expand All @@ -294,17 +289,17 @@ export class LiquorStore<T extends Record<string, any>> 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
}
Expand Down

0 comments on commit f765ef9

Please sign in to comment.