Skip to content

Commit

Permalink
feat: add value
Browse files Browse the repository at this point in the history
  • Loading branch information
everbrez committed Feb 12, 2024
1 parent 7cb11ef commit 05a2807
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/core/src/ModelState/ModelProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import { Action } from './Action';
export class ModelStateProxy<T = any> extends Observable<T> {
protected instance?: ModelState<T>;

isInited?: boolean;

get current(): T {
if (!this.isInited) {
throw new Error('ModelStateProxy: should read value after initialization');
}
return this.instance?.current as T;
}

proxy(instance: ModelState<T>) {
this.instance = instance;
// init;
Expand All @@ -19,6 +28,7 @@ export class ModelStateProxy<T = any> extends Observable<T> {
this.instance.subscribe((action) => {
super.trigger(action);
});
this.isInited = true;
}

next(action: Action<T>) {
Expand All @@ -29,11 +39,15 @@ export class ModelStateProxy<T = any> extends Observable<T> {
export class ModelEventProxy<T = any> extends Observable<T> {
protected instance?: ModelEvent<T>;

isInited?: boolean;

proxy(instance: ModelEvent<T>) {
this.instance = instance;
this.instance.subscribe((action) => {
super.trigger(action);
});

this.isInited = true;
}

next(action?: Action<T>) {
Expand Down

0 comments on commit 05a2807

Please sign in to comment.