Exemplo n.º 1
0
export default function createGroup(definition) {
    let streamsDefs = ('function' === typeof definition) ?
        definition() :
        definition;

    if(('object' !== typeof streamsDefs) ||
        (streamsDefs === null) ||
        Array.isArray(streamsDefs)
    ) {
        throw new TypeError('Cycle Streams Group must be an object.');
    }

    if (this instanceof createGroup) { // jshint ignore:line
        throw new Error('Cannot use `new` operator on `createStreamsGroup()`, it is not a constructor.');
    }

    let streamsWithDeps = mapValues(streamsDefs, (streamFn) => ({
        dependencies: getParametersNames(streamFn)
            .map(_removeUnderscores),
        stream: createStream(streamFn)
    }));

    let group = mapValues(streamsWithDeps, ({ stream }) => stream);

    // add `inject` and `dispose` as not enumerable properties to make them
    // not visible for `each` function
    Object.defineProperty(group, 'inject', {
        enumerable: false,
        value: _makeInjectFn(streamsWithDeps)
    });

    Object.defineProperty(group, 'dispose', {
        enumerable: false,
        value: _makeDisposeFn(group)
    });

    Object.freeze(group);

    return group;
}
Exemplo n.º 2
0
function channels (fns, context) {
  fns = mapValues(fns, function createHandle (fn) {
    return Delegator.allocateHandle(fn.bind(null, context))
  })

  Object.defineProperty(fns, 'toJSON', {
    value: noop,
    writable: true,
    configurable: true,
    enumerable: false
  })

  return fns
}
Exemplo n.º 3
0
 .map((selectedCountries) =>
     mapValues(
         indexBy(selectedCountries, 'code'),
         ({ popularity }) => popularity
     )
Exemplo n.º 4
0
 return function read (callback) {
   assert(++attempts <= 1, 'storage can only be read once')
   return parallel(map(keys, Get), callback)
 }