import { Observable } from 'rxjs'; import { nopeDispatcher } from "../dispatcher/nopeDispatcher"; export type pipe = (scope: { [index: string]: any }, observable: Observable) => Observable export class nopeRemoteObservable { protected _pathes: { get: string, set: string, subscribe: string, } /** * Creates a Remote Dispatcher. * @param _dispatcher * @param options */ constructor( protected _dispatcher: nopeDispatcher, public options: { path: string, } ) { } public get currentRemoteValue() { return this.getRemoteValue() } public async getRemoteValue() { return await this._dispatcher.performCall(this._pathes.get, []) } public async setRemoteValue(value: S) { // Perform an Update. return await this._dispatcher.performCall(this._pathes.set, [value]); } /** * Function to Subscribe a NopeObservable on a Remote. * @param next the callback, which will be called on new Data. * @param options */ public async subscribe(next: (data: K) => void, options: { scope?: { [index: string]: any }, pipe?: pipe } = {}) { return await this._dispatcher.performCall<() => void>(this._pathes.subscribe, [next, options]); } }