diff --git a/packages/store/src/index.ts b/packages/store/src/index.ts index f553e5b..fba4301 100644 --- a/packages/store/src/index.ts +++ b/packages/store/src/index.ts @@ -1,8 +1,6 @@ export type AnyUpdater = (...args: any[]) => any -export type Listener = (opts: { priority: Priority }) => void - -export type Priority = 'high' | 'low' +export type Listener = () => void interface StoreOptions< TState, @@ -13,8 +11,7 @@ interface StoreOptions< listener: Listener, store: Store, ) => () => void - onUpdate?: (opts: { priority: Priority }) => void - defaultPriority?: Priority + onUpdate?: () => void } export class Store< @@ -26,7 +23,6 @@ export class Store< options?: StoreOptions _batching = false _flushing = 0 - _nextPriority: null | Priority = null constructor(initialState: TState, options?: StoreOptions) { this.state = initialState @@ -42,30 +38,14 @@ export class Store< } } - setState = ( - updater: TUpdater, - opts?: { - priority: Priority - }, - ) => { + setState = (updater: TUpdater) => { const previous = this.state this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : (updater as any)(previous) - const priority = opts?.priority ?? this.options?.defaultPriority ?? 'high' - if (this._nextPriority === null) { - this._nextPriority = priority - } else if (this._nextPriority === 'high') { - this._nextPriority = priority - } else { - this._nextPriority = this.options?.defaultPriority ?? 'high' - } - // Always run onUpdate, regardless of batching - this.options?.onUpdate?.({ - priority: this._nextPriority, - }) + this.options?.onUpdate?.() // Attempt to flush this._flush() @@ -76,9 +56,7 @@ export class Store< const flushId = ++this._flushing this.listeners.forEach((listener) => { if (this._flushing !== flushId) return - listener({ - priority: this._nextPriority ?? 'high', - }) + listener() }) }