Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "from/object"

Index

Interfaces

Type aliases

Functions

Type aliases

KeyStreams

KeyStreams<T, K>: {}

Type parameters

  • T

  • K: Keys<T>

Type declaration

    Functions

    Const fromObject

    • 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:

      {
        streams: { ... },
        next(x): void;
        done(): void;
      }

      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.
      • done() - calls ISubscriber.done on all streams

      The optional opts arg is used to customize overall behavior of fromObject and specify shared options for all created streams.

      example
      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
      example
      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

      Type parameters

      • T

      • K: Keys<T>

      Parameters

      Returns StreamObj<T, K>

    Generated using TypeDoc