Class SignalsFactory<IN, OUT, CONFIG, EFF>

A SignalsFactory wraps a SignalsBuild function, allowing for simple Signals composition and manipulation. Via the compose method, two SignalsFactories can be easily composed to a new one. Several convenience methods simplify re-mapping of IN, OUT, CONFIG and EFF. Monadic bind and fmap methods can be used for more complex cases (though 90% of use-cases should be covered by compose, extendSetup, mapInput, mapOutput and mapConfig). SignalsFactory instances are immutable (persistent data structures), hence all methods return a new SignalsFactory instance. (The whole purpose of this class is to provide immutable SignalsBuild composition)

Type Parameters

Hierarchy

  • SignalsFactory

Constructors

Properties

build: SignalsBuild<IN, OUT, CONFIG, EFF>

a pure function mapping from CONFIG to Signals

Methods

  • addEffectId can be used as a short alternative to mapEffects, if you want to add just a single EffectId to the effect-ids.

    Returns

    • a new SignalsFactory with modified effect-ids

    Type Parameters

    • K extends string

      a concrete string to be used as key for the new EffectId

    • ID extends EffectId<any, any, unknown>

      a concrete EffectId type

    Parameters

    • name: AssertNonExistingKey<K, EFF, "any name not in keyof EFF">

      the name of the new EffectId

    • idGetter: ((config: CONFIG) => ID)

      a function returning the new EffectId

        • (config: CONFIG): ID
        • Parameters

          • config: CONFIG

          Returns ID

    Returns SignalsFactory<IN, OUT, CONFIG, AddEffectId<EFF, K, ID>>

  • addInputId can be used as a short alternative to mapInput, if you want to add just a single SignalId to the input signal ids.

    Returns

    • a new SignalsFactory with modified input signals

    Type Parameters

    • K extends string

      a concrete string to be used as key for the new SignalId

    • ID extends SignalId<any>

      a concrete SignalId type

    Parameters

    • name: AssertNonExistingKey<K, IN, "any name not in keyof IN">

      the name of the new SignalId

    • idGetter: ((config: CONFIG) => ID)

      a function returning the new SignalId

        • (config: CONFIG): ID
        • Parameters

          • config: CONFIG

          Returns ID

    Returns SignalsFactory<AddSignalId<IN, K, ID>, OUT, CONFIG, EFF>

  • addOutputId can be used as a short alternative to mapOutput, if you want to add just a single SignalId to the output signal ids.

    Returns

    • a new SignalsFactory with modified output signals

    Type Parameters

    • K extends string

      a concrete string to be used as key for the new SignalId

    • ID extends SignalId<any>

      a concrete SignalId type

    Parameters

    • name: AssertNonExistingKey<K, OUT, "any name not in keyof OUT">

      the name of the new SignalId

    • idGetter: ((config: CONFIG) => ID)

      a function returning the new SignalId

        • (config: CONFIG): ID
        • Parameters

          • config: CONFIG

          Returns ID

    Returns SignalsFactory<IN, AddSignalId<OUT, K, ID>, CONFIG, EFF>

  • This method implements monadic-bind for the SignalsFactory. It takes as argument a pure function that implements SignalsMapToFactory<IN, OUT, CONFIG, EFF, IN2, OUT2, CONFIG2, EFF2>, hence a function taking SignalsBuild<IN, OUT, CONFIG, EFF> as argument and returning a SignalsFactory<IN2, OUT2, CONFIG2, EFF2>. The result of bind is a new SignalsFactory that uses the SignalsBuild<IN2, OUT2, CONFIG2, EFF2>::build of the factory returned from the mapper (hence the result of bind is not the same instance as returned by the mapper).

    Returns

    • a new SignalsFactory<IN2, OUT2, CONFIG2, EFF2>

    Type Parameters

    Parameters

    • mapper: BindMapper<IN, OUT, CONFIG, EFF, IN2, OUT2, CONFIG2, EFF2>

      a pure function mapping from SignalsBuild<IN, OUT, CONFIG, EFF> to SignalsFactory<IN2, OUT2, CONFIG2, EFF2>

    Returns SignalsFactory<IN2, OUT2, CONFIG2, EFF2>

  • The compose method takes a second SignalsFactory2 and returns a new SignalsFactory that represents the composition of this SignalsFactory and the argument SignalsFactory2. You can re-map the input, output, configuration and effects of the resulting composed SignalsFactory by using mapInput, mapOutput, mapConfig and mapEffects correspondingly (as well as the many other convenience methods).

    Returns

    • the SignalsFactory resulting from the composition of this SignalsFactory and SignalsFactory2

    Type Parameters

    Parameters

    Returns ComposedFactory<IN, OUT, CONFIG, EFF, IN2, OUT2, CONFIG2, EFF2>

  • The connect method offers an easy way to connect an output signal to an input signal. It takes the name of an output-id (a key of OUT) as first argument and the name of an input-id (a key of IN) as second argument. If keepInputId is set to true, it returns a new SignalsFactory of the same type as this SignalsFactory, but with an extended setup logic, that connects the Signal<S extends T> that corresponds to the named output-id to a new Signal<T> corresponding to the named input-id. If keepInputId is set to false, it also extends the setup logic to connect the corresponding signal-ids, but in addition the specified input-id will be excluded from the IN-type of the resulting factory. (also see store.connect documentation, as this is used under the hood) Typescript will enforce that both names (keys) map to compatible signal ids, hence if KIN corresponds to SignalId<T>, then KOUT must correspond to SignalId<S extends T> (though one might be an EventId and the other a BehaviorId). Even though you only use strings as arguments, this method is still type-safe and will not compile if you try to specify names of non-existing or incompatible ids.

    Returns

    • a new SignalsFactory with the concrete type depending on the keepInputId argument

    Type Parameters

    • KIN extends string | number | symbol

    • KOUT extends string | number | symbol

    • B extends boolean

    Parameters

    • outputName: KOUT

      a key of OUT, where OUT[outputName] must be of type Signal<S extends T>

    • inputName: KIN

      a key of IN, where IN[toName] must be of type Signal<T>

    • keepInputId: B

      if set to false, the input-id corresponding to toName will be removed from the resulting factories' IN

    Returns B extends true ? SignalsFactory<IN, OUT, CONFIG, EFF> : SignalsFactory<Omit<IN, KIN>, OUT, CONFIG, EFF>

  • The connectId method is a more general version of the connect method. In contrast to connect, it does not take the name of an OUT signal-id, but instead directly a signal-id (thus, some arbitrary signal-id can be used). Everything else works like connect, so please see the corresponding documentation there.

    Returns

    • a new SignalsFactory with the concrete type depending on the keepInputId argument

    Type Parameters

    Parameters

    • fromId: ID

      a Signal<S extends T>

    • inputName: K

      a key of IN, where IN[toName] must be of type Signal<T>

    • keepInputId: B

      if set to false, the input-id corresponding to toName will be removed from the resulting factories' IN

    Returns B extends true ? SignalsFactory<IN, OUT, CONFIG, EFF> : SignalsFactory<Omit<IN, K>, OUT, CONFIG, EFF>

  • The connectObservable method is even more general compared to the connect and connectId methods. In contrast to the previous two, its first argument is a function that takes store, output and config as arguments and returns an observable. For the other arguments, please see the documentation of the connect method.

    Returns

    • a new SignalsFactory with the concrete type depending on the keepInputId argument

    Type Parameters

    • K extends string | number | symbol

    • S extends any

    • O extends Observable<S, O>

    • B extends boolean

    Parameters

    • sourceGetter: ((args: SignalsFactoryArgs<IN, OUT, CONFIG, EFF>) => O)

      a function returning an Observable<S extends T>

    • inputName: K

      a key of IN, where IN[toName] must be of type Signal<T>

    • keepInputId: B

      if set to false, the input-id corresponding to toName will be removed from the resulting factories' IN

    Returns B extends true ? SignalsFactory<IN, OUT, CONFIG, EFF> : SignalsFactory<Omit<IN, K>, OUT, CONFIG, EFF>

  • The extendSetup method takes as argument a function that implements ExtendSetup<IN, OUT, CONFIG, EFF>. It returns a new SignalsFactory of the same type as this SignalsFactory, but with a wrapped SignalsBuild that extends the code executed in the Signals setup method by the provided code.

    Returns

    • a new SignalsFactory with extended store setup

    Parameters

    • extend: ExtendSetup<IN, OUT, CONFIG, EFF>

      a function extending the setup method of the Signals produced by the SignalsBuild of the resulting SignalsFactory

    Returns SignalsFactory<IN, OUT, CONFIG, EFF>

  • This method implements the functor-fmap for the SignalsFactory. It takes as argument a pure function that implements BuildMapper<IN, OUT, CONFIG, EFF, IN2, OUT2, CONFIG2, EFF2>, hence a function taking SignalsBuild<IN, OUT, CONFIG, EFF> as argument and returning a SignalsBuild<IN2, OUT2, CONFIG2, EFF2>. The result of fmap is a new SignalsFactory that uses the SignalsBuild<IN2, OUT2, CONFIG2, EFF2> returned from the mapper.

    Returns

    • a new SignalsFactory<IN2, OUT2, CONFIG2, EFF2>

    Type Parameters

    Parameters

    • mapper: BuildMapper<IN, OUT, CONFIG, EFF, IN2, OUT2, CONFIG2, EFF2>

      a pure function mapping from SignalsBuild<IN, OUT, CONFIG, EFF> to SignalsBuild<IN2, OUT2, CONFIG2, EFF2>

    Returns SignalsFactory<IN2, OUT2, CONFIG2, EFF2>

  • The mapConfig method takes as argument a pure function that implements MapConfig<CONFIG, CONFIG2>. It returns a new SignalsFactory<IN, OUT, CONFIG2, EFF>.

    Returns

    • a new SignalsFactory with different Configuration type

    Type Parameters

    Parameters

    • mapper: MapConfig<CONFIG, CONFIG2>

      a pure function mapping CONFIG2 to CONFIG

    Returns SignalsFactory<IN, OUT, CONFIG2, EFF>

  • The mapEffects method takes as argument a pure function that implements MapEffectIds<EFF, EFF2, CONFIG>. It returns a new SignalsFactory<IN, OUT, CONFIG, EFF2>.

    Returns

    • a new SignalsFactory with different effect-ids

    Type Parameters

    Parameters

    • mapper: MapEffectIds<EFF, EFF2, CONFIG>

      a pure function mapping from EFF to EFF2

    Returns SignalsFactory<IN, OUT, CONFIG, EFF2>

  • The mapInput method takes as argument a pure function that implements MapSignalIds<IN, IN2>. It returns a new SignalsFactory<IN2, OUT, CONFIG, EFF>.

    Returns

    • a new SignalsFactory with different input signals

    Type Parameters

    Parameters

    • mapper: MapSignalIds<IN, IN2, CONFIG>

      a pure function mapping from IN to IN2

    Returns SignalsFactory<IN2, OUT, CONFIG, EFF>

  • The mapOutput method takes as argument a pure function that implements MapSignalIds<OUT, OUT2>. It returns a new SignalsFactory<IN, OUT2, CONFIG, EFF>.

    Returns

    • a new SignalsFactory with different output signals

    Type Parameters

    Parameters

    • mapper: MapSignalIds<OUT, OUT2, CONFIG>

      a pure function mapping from OUT to OUT2

    Returns SignalsFactory<IN, OUT2, CONFIG, EFF>

  • mapOutputBehavior can be used to transfrom an output-behavior of type TOLD to a new behavior of type TNEW, keeping the output-id-name. Thus, this is a short form for adding a new behavior based on an existing output-behavior, then removing the ID of the existing one from output and finally, putting the ID of the new behavior into output under the removed name of the existing behavior. Hence, this transforms from SignalsFactory<IN, OUT, CONFIG> to SignalsFactory<IN, OUT2, CONFIG> with OUT2 having the same keys as OUT, but OUT2[KOUT] having type TNEW and OUT[KOUT] having type TOLD

    Returns

    • a new SignalsFactory with a modified output signal

    Type Parameters

    • TNEW

      value-type of the OUT2[KOUT] BehaviorId after mapping

    • KOUT extends string | number | symbol

      a concrete output key mapping to a BehaviorId<any>

    Parameters

    Returns SignalsFactory<IN, AddOrReplaceId<OUT, KOUT, DerivedId<TNEW>>, CONFIG, EFF>

  • removeEffectId can be used as a short alternative to mapEffects, if you want to remove just a single EffectId from the effect-ids.

    Returns

    • a new SignalsFactory with modified effect-ids

    Type Parameters

    • K extends string | number | symbol

      a concrete key of the effect-ids of this factory

    Parameters

    • name: K

      the name of in NameToEffectIds to be removed

    Returns SignalsFactory<IN, OUT, CONFIG, Omit<EFF, K>>

  • removeInputId can be used as a short alternative to mapInput, if you want to remove just a single SignalId from the input signal ids.

    Returns

    • a new SignalsFactory with modified input signals

    Type Parameters

    • K extends string | number | symbol

      a concrete K of the input signals of this factory

    Parameters

    • name: K

      the name of the SignalId to be removed

    Returns SignalsFactory<Omit<IN, K>, OUT, CONFIG, EFF>

  • removeOutputId can be used as a short alternative to mapOutput, if you want to remove just a single SignalId from the output signal ids.

    Returns

    • a new SignalsFactory with modified output signals

    Type Parameters

    • K extends string | number | symbol

      a concrete K of the output signals of this factory

    Parameters

    • name: K

      the name of the SignalId to be removed

    Returns SignalsFactory<IN, Omit<OUT, K>, CONFIG, EFF>

  • renameEffectId can be used as a short alternative to mapEffects, if you want to change the name of a single EffectId in the effect-ids.

    Returns

    • a new SignalsFactory with modified effect-ids

    Type Parameters

    • K1 extends string | number | symbol

      a concrete key of EFF

    • K2 extends string

      the new name for EFF[K1]

    Parameters

    • oldName: K1

      the old key

    • newName: K2

      the new key

    Returns SignalsFactory<IN, OUT, CONFIG, RenameEffectId<EFF, K1, K2>>

  • renameInputId can be used as a short alternative to mapInput, if you want to change the name of a single SignalId in the input signal ids.

    Returns

    • a new SignalsFactory with modified input signals

    Type Parameters

    • K1 extends string | number | symbol

      a concrete key of IN

    • K2 extends string

      the new name for IN[K1]

    Parameters

    • oldName: K1

      the old key

    • newName: K2

      the new key

    Returns SignalsFactory<RenameId<IN, K1, K2>, OUT, CONFIG, EFF>

  • renameOutputId can be used as a short alternative to mapOutput, if you want to change the name of a single SignalId in the output signal ids.

    Returns

    • a new SignalsFactory with modified output signals

    Type Parameters

    • K1 extends string | number | symbol

      a concrete key of OUT

    • K2 extends string

      the new name for OUT[K1]

    Parameters

    • oldName: K1

      the old key

    • newName: K2

      the new key

    Returns SignalsFactory<IN, RenameId<OUT, K1, K2>, CONFIG, EFF>

  • useExistingEffect can be used to get a factory that uses an existing effect as the effect referenced by a given effect-id generated by this factory.

    Returns

    • a new SignalsFactory with the concrete type depending on the keepInputId argument

    Type Parameters

    • InputType

    • ResultType

    • K extends string | number | symbol

      a concrete key of the effect-ids of this factory

    • B extends boolean

    Parameters

    • name: K

      a name from this factory's effects, mapping to a concrete EffectId

    • idGetter: ((config: CONFIG) => EffectId<InputType, ResultType, unknown>)

      a function, getting the config as argument and returning the EffectId of an existing effect that should be used for the EffectId specified by K.

        • (config: CONFIG): EffectId<InputType, ResultType, unknown>
        • Parameters

          • config: CONFIG

          Returns EffectId<InputType, ResultType, unknown>

    • keepEffectId: B

      specifies whether the resulting SignalsFactory should still produce the EffectId referenced by K.

    Returns B extends true ? SignalsFactory<IN, OUT, CONFIG, EFF> : SignalsFactory<IN, OUT, CONFIG, Omit<EFF, K>>

Generated using TypeDoc