diff options
Diffstat (limited to 'cds-ui/designer-client/src/app/common/core/stores')
-rw-r--r-- | cds-ui/designer-client/src/app/common/core/stores/Store.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/cds-ui/designer-client/src/app/common/core/stores/Store.ts b/cds-ui/designer-client/src/app/common/core/stores/Store.ts new file mode 100644 index 000000000..1d5b0afc1 --- /dev/null +++ b/cds-ui/designer-client/src/app/common/core/stores/Store.ts @@ -0,0 +1,22 @@ +import {Observable, BehaviorSubject} from 'rxjs'; +import { Injectable } from '@angular/core'; + +export class Store<T> { + state$: Observable<T>; + private subject: BehaviorSubject<T>; + + protected constructor(initialState: T) { + this.subject = new BehaviorSubject(initialState); + this.state$ = this.subject.asObservable(); + } + + get state(): T { + return this.subject.getValue(); + } + + protected setState(nextState: T): void { + console.log('setting state', this.subject); + this.subject.next(nextState); + } + +} |