UNPKG

@connectv/core

Version:

agent-based reactive programming library for typescript/javascript

75 lines (74 loc) 2.21 kB
import { ContextType } from './types'; /** * * When the same key appears in multiple [emissions](https://connective.dev/docs/emission), * with conflicting values, when the emissions are merged, the corresponding values are * stored within an instance of `MergedEmissionContextVal`. You can read these values using * `.values` property: * * ```typescript * myFlow.observable.subscribe(emission => { * if (emission.context.someKey instanceof MergedEmissionContextVal) * emission.context.someKey.values.forEach(value => handle(value)); * else * handle(emission.context.someKey); * }); * ``` * */ export declare class MergedEmissionContextVal { readonly values: any[]; constructor(values: any[]); } /** * * Represents emissions passing through reactive flows. * mainly has a `.value` property, which is the value that this emission is wrapping, * and `.context` property, which is the context of the emission. * * [read more here](https://connective.dev/docs/emission). * */ export declare class Emission { readonly value: any; readonly context: ContextType; /** * * @param value the value of the emission * @param context the context of the emission * */ constructor(value?: any, context?: ContextType); /** * * Will create a merged emission from given emissions. * * @param emissions the emissions to merge * @param value the value to set on the forked emission (by default will be an array of the merged emissions' values). * */ static from(emissions: Emission[], value?: any): Emission; /** * * Creates a new `Emission` with the same context but the new value * * @param value * */ fork(value: any): Emission; } /** * * Creates an emission with given value and context. You can feed this object to * your reactive flows using [`source()`](https://connective.dev/docs/source) for example: * * ```typescript * let a = source(); * a.emit(emission(42, { reason: 'it is the ultimate answer' })); * ``` * * @param value * @param context */ export declare function emission(value?: any, context?: ContextType): Emission; export default emission;