UNPKG

@sustain/core

Version:

Sustain is a Framework that is barely used despedcies to make stable and sustainable apps

30 lines (27 loc) 652 B
import {BehaviorSubject} from 'rxjs'; import {filter} from 'rxjs/operators'; export class SustainContext { subject = new BehaviorSubject({}); constructor() {} context: any = {}; set(key: string, value: any) { this.context[key] = value; this.subject.next({ action: key, value, }); } sub() { return this.subject; } get(key: string) { return this.context[key]; } on(key: string) { return this.subject.pipe(filter((payload: any) => payload.action === key)); } } const injectedContext = new SustainContext(); export function getContext() { return injectedContext; }