Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben-Arushanyan committed Oct 3, 2023
1 parent 9a28bd7 commit e93709e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isFunction, eq, memoizeByArgs } from './utils'
class Store {
#emitter_key = Symbol()
#emitter = new SingularEventEmitter(this.#emitter_key)
#order = 0;

state
prevState
Expand All @@ -21,14 +22,18 @@ class Store {
if (!eq(newState, this.state)) {
this.prevState = this.state
this.state = newState
this.#emitter.unlock(this.#emitter_key).emit()
this.#emitter.unlock(this.#emitter_key).emit(++this.#order)
}
}

subscribe = (cb) => {
cb = memoizeByArgs(cb)
const _cb = () => {
cb(this.state, this.prevState)
let _order = 0;
const _cb = (order) => {
if (order > _order) {
cb(this.state, this.prevState)
_order = order
}
}

this.#emitter.on(_cb)
Expand Down

0 comments on commit e93709e

Please sign in to comment.