state/src/index.ts
export {Getter, Setter, Lens, Scope, Reducer, MainFn} from './types';
export {StateSource, isolateSource, isolateSink} from './StateSource';
export {Instances, CollectionOptions} from './Collection';
/**
* Given a Cycle.js component that expects a state *source* and will
* output a reducer *sink*, this function sets up the state management
* mechanics to accumulate state over time and provide the state source. It
* returns a Cycle.js component which wraps the component given as input.
* Essentially, it hooks up the reducers sink with the state source as a cycle.
*
* Optionally, you can pass a custom name for the state channel. By default,
* the name is 'state' in sources and sinks, but you can change that to be
* whatever string you wish.
*
* @param {Function} main a function that takes `sources` as input and outputs
* `sinks`.
* @param {String} name an optional string for the custom name given to the
* state channel. By default, it is the string 'state'.
* @return {Function} a component that wraps the main function given as input,
* adding state accumulation logic to it.
* @function withState
*/
export {withState} from './withState';
/**
* 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.
* @param {Object} opts a configuration object with the following fields:
* - `item: function`, a Cycle.js component for each item in the collection.
* - `collectSinks: function`, a function that describes how to collect the
* sinks from all item instances.
* - `itemKey: function`, a function from item state to item (unique) key.
* - `itemScope: function`, a function from item key to isolation scope.
* - `channel: string`, choose the channel name where the StateSource exists.
* @return {Function} a component that displays many instances of the item
* component.
* @function makeCollection
*/
export {makeCollection} from './Collection';