From e93709edc05981e46536aff24a53ab4a36fc48bf Mon Sep 17 00:00:00 2001 From: Ruben Arushanyan Date: Wed, 4 Oct 2023 02:46:31 +0400 Subject: [PATCH] improvements --- src/Store.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Store.js b/src/Store.js index 3085a9e..b1d0315 100644 --- a/src/Store.js +++ b/src/Store.js @@ -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 @@ -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)