Module: "urx/src/actions"#

urx Actions operate on streams - publish publishes data in a stream, and subscribe attaches a subscription to a stream.

Index#

Interfaces#

Functions#

Functions#

connect#

â–¸ connect<T>(emitter: Emitter<T>, publisher: Publisher<T>): Unsubscribe

Defined in urx/src/actions.ts:132

Connects two streams - any value emitted from the emitter will be published in the publisher.

const foo = stream<number>();
const bar = stream<number>();
subscribe(bar, (value) => console.log(`Bar emitted ${value}`));
connect(foo, bar);
publish(foo);

Type parameters:#

Name
T

Parameters:#

NameType
emitterEmitter<T>
publisherPublisher<T>

Returns: Unsubscribe

an Unsubscribe handle which will disconnect the two streams.


getValue#

â–¸ getValue<T>(depot: StatefulStream<T>): T

Defined in urx/src/actions.ts:116

Extracts the current value from a stateful stream. Use it only as an escape hatch, as it violates the concept of reactive programming.

const foo = statefulStream(42);
console.log(getValue(foo));

Type parameters:#

Name
T

Parameters:#

NameType
depotStatefulStream<T>

Returns: T


handleNext#

â–¸ handleNext<T>(emitter: Emitter<T>, subscription: Subscription<T>): Unsubscribe

Defined in urx/src/actions.ts:146

Executes the passed subscription at most once, for the next emit from the emitter.

const foo = stream<number>()
handleNext(foo, value => console.log(value)) // called once, with 42
publish(foo, 42)
publish(foo, 43)

Type parameters:#

Name
T

Parameters:#

NameType
emitterEmitter<T>
subscriptionSubscription<T>

Returns: Unsubscribe

an Unsubscribe handle to unbind the subscription if necessary.


publish#

â–¸ publish<T>(publisher: Publisher<T>, value: T): void

Defined in urx/src/actions.ts:92

Publishes the value into the passed Publisher.

const foo = stream<number>();
publish(foo, 42);

Type parameters:#

Name
T

Parameters:#

NameType
publisherPublisher<T>
valueT

Returns: void


reset#

â–¸ reset(emitter: Emitter<any>): void

Defined in urx/src/actions.ts:105

Clears all subscriptions from the Emitter.

const foo = stream<number>();
subscribe(foo, (value) => console.log(value));
reset(foo);
publish(foo, 42);

Parameters:#

NameType
emitterEmitter<any>

Returns: void


subscribe#

â–¸ subscribe<T>(emitter: Emitter<T>, subscription: Subscription<T>): Unsubscribe

Defined in urx/src/actions.ts:80

Subscribes the specified Subscription to the updates from the Emitter. The emitter calls the subscription with the new data each time new data is published into it.

const foo = stream<number>();
subscribe(foo, (value) => console.log(value));

Type parameters:#

Name
T

Parameters:#

NameType
emitterEmitter<T>
subscriptionSubscription<T>

Returns: Unsubscribe

an Unsubscribe handle - calling it will unbind the subscription from the emitter.

const foo = stream<number>();
const unsub = subscribe(foo, (value) => console.log(value));
unsub();