From 73ba955e344c8ccedd43235495ef8b72b5a2b6fd Mon Sep 17 00:00:00 2001 From: Ricardo Cino Date: Wed, 22 Jun 2022 00:32:18 +0200 Subject: chore: Transform AppStore.js into Typescript (#329) * turn actions into typescript * correct tsconfig * added TypedStore --- src/stores/lib/TypedStore.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/stores/lib/TypedStore.ts (limited to 'src/stores/lib/TypedStore.ts') diff --git a/src/stores/lib/TypedStore.ts b/src/stores/lib/TypedStore.ts new file mode 100644 index 000000000..5d8bf3bbd --- /dev/null +++ b/src/stores/lib/TypedStore.ts @@ -0,0 +1,46 @@ +import { computed, IReactionPublic, observable } from 'mobx'; +import { Actions } from 'src/actions/lib/actions'; +import { ApiInterface } from 'src/api'; +import { Stores } from 'src/stores.types'; +import Reaction from './Reaction'; + +export default abstract class TypedStore { + _reactions: Reaction[] = []; + + @observable _status: any = null; + + @computed get actionStatus() { + return this._status || []; + } + + set actionStatus(status) { + this._status = status; + } + + constructor( + public stores: Stores, + public api: ApiInterface, + public actions: Actions, + ) {} + + registerReactions(reactions: { (r: IReactionPublic): void }[]): void { + for (const reaction of reactions) { + this._reactions.push(new Reaction(reaction)); + } + } + + public abstract setup(): void; + + initialize(): void { + this.setup(); + for (const reaction of this._reactions) reaction.start(); + } + + teardown(): void { + for (const reaction of this._reactions) reaction.stop(); + } + + resetStatus(): void { + this._status = null; + } +} -- cgit v1.2.3-70-g09d2