kosich / rxjs-proxify

Turns a Stream of Objects into an Object of Streams
MIT License
35 stars 3 forks source link

WIP: extensibility draft #4

Open kosich opened 3 years ago

kosich commented 3 years ago

This allows adding functions on the proxy fields (fix #3)

E.g.:

interface Extension {
  readValue<S>(this:S): S extends ObservableProxy<infer A, unknown> ? A : never;
}

const x: Extension = {
  readValue() { return this… }
}

const source = proxify(of({ a: 1 }, { a: 2 }), x);
const d = source.a.readValue() // d: number

This might be handy if combined with rxjs-autorun:

// RxJS :: Autorun + Proxify 
const s = statify({ a: '🐰', b: '🏑' });
autorun(() => s.b.$() + s.a._()); //🏑🐰
s.b.next('πŸ›Έ'); //πŸ›ΈπŸ°

I don't quite like the typing output and code should be refactored to include this feature. Also, it's not clear at what level should this extension be applied and when dropped (observable/subject/behaviorSubject)