derive()

@mvuijs/core / rx / derive

derive() #

Create a DerivedState from a set of State or existing DerivedState objects. The last argument is a function that will taking the values of the State/DerivedState objects defined in all prior arguments. There are overloads for providing up to eight parent State/DerivedState objects.

See DerivedState for details.

Example #

const s1 = new State(1);
const s2 = new State(2);
rx.derive(s1, s2, (v1, v2) => v1 + v2)
  .subscribe(console.log); // => logs 3
s2.next(3); // => logs 5

Signature #

derive<R, A, B>(
  sa: Derivable<A>, 
  sb: Derivable<B>, 
  def: Function, 
  equality?: Equality): DerivedState<R>;

Type parameters #

  • R
  • A
  • B

Parameters #

Name Type
sa Derivable <A>
sb Derivable <B>
def (a: A, b: B) => R
equality? Equality

Returns #

DerivedState <R>

Defined in: packages/core/src/rx/derived-state.ts:170