Takes an arbitrary object src and object of options (see StreamObjOpts). Creates a new object and for each selected key creates a new stream, optionally seeded with the key's value in src. Returns new object of streams.
remarks
The structure of the returned object is as follows:
All streams will be stored under streams. The next() and done() functions/methods allow the object itself to be used as subscriber for an upstream subscribable (see 2nd example below):
next() - takes a object of same type as src and feeds each key's new value into its respective stream. If the defaults option is given, undefined key values are replaced with their specified default. If dedupe is enabled (default) only changed values (as per equiv predicate option) will be propagated downstream.
Takes an arbitrary object
src
and object of options (see StreamObjOpts). Creates a new object and for each selected key creates a new stream, optionally seeded with the key's value insrc
. Returns new object of streams.The structure of the returned object is as follows:
{ streams: { ... }, next(x): void; done(): void; }
All streams will be stored under
streams
. Thenext()
anddone()
functions/methods allow the object itself to be used as subscriber for an upstream subscribable (see 2nd example below):next()
- takes a object of same type assrc
and feeds each key's new value into its respective stream. If thedefaults
option is given,undefined
key values are replaced with their specified default. Ifdedupe
is enabled (default) only changed values (as perequiv
predicate option) will be propagated downstream.done()
- calls ISubscriber.done on all streamsThe optional
opts
arg is used to customize overall behavior offromObject
and specify shared options for all created streams.type Foo = { a?: number; b: string; }; const obj = fromObject(<Foo>{ a: 1, b: "foo" }) obj.streams.a.subscribe(trace("a")) // a 1 obj.streams.b.subscribe(trace("b")) // b foo obj.next({ b: "bar" }) // a undefined // b bar
const obj = fromObject(<Foo>{}, ["a", "b"], { initial: false }); obj.streams.a.subscribe(trace("a")); obj.streams.b.subscribe(trace("b")); const src = subscription<Foo, Foo>(); // use as subscriber src.subscribe(obj); src.next({ a: 1, b: "foo" }); // a 1 // b foo