Skip to content

Commit

Permalink
add immer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben-Arushanyan committed Oct 3, 2023
1 parent 6c9672e commit 130c91c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"jest": "^29.0.3"
},
"dependencies": {
"immer": "^10.0.3",
"secure-event-emitter": "^4.3.5"
}
}
9 changes: 8 additions & 1 deletion src/Store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SingularEventEmitter } from 'secure-event-emitter'
import { isFunction, eq, memoizeByArgs } from './utils'

import { produce } from 'immer'

class Store {
#emitter_key = Symbol()
Expand All @@ -26,6 +26,13 @@ class Store {
}
}

updateStateImmer = (cb) => {
if (!isFunction(cb)) {
throw new TypeError('[[updateStateImmer()]] argument must be a function');
}
this.updateState(() => produce(this.state, cb))
}

subscribe = (cb) => {
cb = memoizeByArgs(cb)
const _cb = (order) => {
Expand Down

0 comments on commit 130c91c

Please sign in to comment.