Extensibility
kosich opened this issue Β· comments
Kostia P commented
It'd be good to have ability to extend some levels of proxify, e.g.:
// create a state
const state = createState({ count: 0, timer: 100 });
// listen to state changes
state.count.subscribe(c => console.log('C:', c)); // > C:0
// write to the state
state.count.next(1); // > C:1
// reset the state
state.next({ timer: 2, count: 2 }) // > C:2
state.count += 1; // > C:3
state.count.next(3); // ignored: same value
// read current values:
console.log(state.timer + state.count); // > 2 + 3 = 5
OR to be able to add rxjs-autorun functions, e.g.:
// pseudocode
// state.js
import { $, _ } from 'rxjs-autorun';
export const State = v => proxify(
new BehaviorSubject(v), // base
{ $, _ } // extender
);
// index.js
import { run } from 'rxjs-autorun';
import { State } from './state';
const state = State(0);
run(() => state.$ + ' π'); // > 0 π
state.next(1); // > 1 π