import { Stream } from 'xstream'; import { InternalInstances, ItemKeyFn, ItemScopeFn } from './types'; /** * An object representing all instances in a collection of components. Has the * methods pickCombine and pickMerge to get the combined sinks of all instances. */ export declare class Instances { private _instances$; constructor(instances$: Stream>); /** * Like `merge` in xstream, this operator blends multiple streams together, but * picks those streams from a collection of component instances. * * Use the `selector` string to pick a stream from the sinks object of each * component instance, then pickMerge will merge all those picked streams. * * @param {String} selector a name of a channel in a sinks object belonging to * each component in the collection of components. * @return {Function} an operator to be used with xstream's `compose` method. */ pickMerge(selector: string): Stream; /** * Like `combine` in xstream, this operator combines multiple streams together, * but picks those streams from a collection of component instances. * * Use the `selector` string to pick a stream from the sinks object of each * component instance, then pickCombine will combine all those picked streams. * * @param {String} selector a name of a channel in a sinks object belonging to * each component in the collection of components. * @return {Function} an operator to be used with xstream's `compose` method. */ pickCombine(selector: string): Stream>; } export interface CollectionOptions { /** * The Cycle.js component for each item in this collection. Should be just a * function from sources to sinks. */ item: (so: So) => Si; /** * A function that describes how to collect all the sinks from all item * instances. The instances argument is an object with two methods: pickMerge * and pickCombine. These behave like xstream "merge" and "combine" operators, * but are applied to the dynamic collection of all item instances. * * This function should return an object of sinks. This is what the collection * component will output as its sinks. */ collectSinks: (instances: Instances) => any; /** * Specify, from the state object for each item in the collection, a key for * that item. This avoids bugs when the collection grows or shrinks, as well * as helps determine the isolation scope for each item, when specifying the * `itemScope` option. This function also takes the index number (from the * corresponding entry in the state array) as the second argument. * * Example: * * ```js * itemKey: (itemState, index) => itemState.key * ``` */ itemKey?: ItemKeyFn; /** * Specify each item's isolation scope, given the item's key. * * Pass a function which describes how to create the isolation scopes for each * item component, given that item component's unique key. The unique key for * each item was defined by the `itemKey` option. */ itemScope?: ItemScopeFn; /** * Choose the channel name where the StateSource exists. Typically this is * 'onion', but you can customize it if your app is using another name. It is * used for referencing the correct source used for describing * growing/shrinking of the collection of items. */ channel?: string; } /** * Returns a Cycle.js component (a function from sources to sinks) that * represents a collection of many item components of the same type. * * Takes an "options" object as input, with the required properties: * - item * - collectSinks * * And the optional properties: * - itemKey * - itemScope * - channel * * The returned component, the Collection, will use the state source passed to * it (through sources) to guide the dynamic growing/shrinking of instances of * the item component. * * Typically the state source should emit arrays, where each entry in the array * is an object holding the state for each item component. When the state array * grows, the collection will automatically instantiate a new item component. * Similarly, when the state array gets smaller, the collection will handle * removal of the corresponding item instance. */ export declare function makeCollection(opts: CollectionOptions): (sources: any) => any;