import { BehaviorSubject } from 'rxjs' import { SimpleSubscribable, Updatable } from '../utils' /** * Subject-like object whose state can be updated. * * @typeParam T type of the state */ export interface UpdatableSubscribable extends Updatable, SimpleSubscribable { } /** * Base class for every RxJS store. * * @typeParam T type of the store's state */ export class Store extends BehaviorSubject implements UpdatableSubscribable { /** * @inheritDoc */ update (updater: (prev: T) => T): T { const originalValue = this.getValue() const newValue = updater(originalValue) if (newValue !== originalValue) { this.next(newValue) } return newValue } }