cycle-gear
Advanced tools
Comparing version 7.1.4 to 7.2.0
@@ -35,2 +35,6 @@ import { Observable } from 'xstream'; | ||
export interface MotorOptions extends PedalOptions { | ||
/** | ||
* Gears are only ever added cumulatively, never removed/changed | ||
*/ | ||
cumulative?: boolean; | ||
defaultConnector?: ToothConnector<any, any, any, any>; | ||
@@ -40,2 +44,2 @@ connectors?: Map<string, ToothConnector<any, any, any, any>>; | ||
export declare function pedal(transmission: Transmission, {defaultGear, defaultFilter, sinkMap, sourcesWrapper}?: PedalOptions): (sources: any) => {}; | ||
export declare function motor(gearbox: Gearbox, {defaultGear, defaultFilter, defaultConnector, sourcesWrapper, connectors, sinkMap}?: MotorOptions): (sources: any) => {}; | ||
export declare function motor(gearbox: Gearbox, {defaultGear, defaultFilter, defaultConnector, cumulative, sourcesWrapper, connectors, sinkMap}?: MotorOptions): (sources: any) => {}; |
@@ -97,3 +97,3 @@ import { adapt } from '@cycle/run/lib/adapt'; | ||
const defaultReduce = (acc, [cur, gear]) => (Object.assign({}, acc, { [gear.name || '?']: cur })); | ||
function spinGears(sources, defaultIntent, defaultModel, defaultCatch, teeth, toothFilter, toothView, sourcesWrapper, defaultConnector, connectors) { | ||
function spinGears(sources, defaultIntent, defaultModel, defaultCatch, teeth, toothFilter, toothView, cumulative, sourcesWrapper, defaultConnector, connectors) { | ||
const spinCache = new WeakMap(); | ||
@@ -105,3 +105,3 @@ const spinner = spinGear(sources, defaultIntent, defaultModel, defaultCatch, sourcesWrapper, teeth, toothFilter, toothView, true, defaultConnector, connectors); | ||
const cached = spinCache.get(gear); | ||
if (cached) { | ||
if (!cumulative && cached) { | ||
spins.push(cached); | ||
@@ -118,3 +118,3 @@ } | ||
} | ||
export function motor(gearbox, { defaultGear = { intent: () => ({}), model: () => xs.of({}), teeth: {} }, defaultFilter = () => true, defaultConnector = {}, sourcesWrapper = (sources) => sources, connectors = new Map(), sinkMap = new Map() } = {}) { | ||
export function motor(gearbox, { defaultGear = { intent: () => ({}), model: () => xs.of({}), teeth: {} }, defaultFilter = () => true, defaultConnector = {}, cumulative = false, sourcesWrapper = (sources) => sources, connectors = new Map(), sinkMap = new Map() } = {}) { | ||
const { defaultIntent, defaultModel, defaultCatch, teeth, toothFilter, toothView } = defaultsAndHelpers(defaultGear, defaultFilter); | ||
@@ -129,12 +129,29 @@ return (sources) => { | ||
} | ||
const spin = xs.fromObservable(gears) | ||
.map(spinGears(sources, defaultIntent, defaultModel, defaultCatch, teeth, toothFilter, toothView, sourcesWrapper, defaultConnector, connectors)) | ||
.startWith([]) | ||
.remember(); | ||
let spin = xs.fromObservable(gears) | ||
.map(spinGears(sources, defaultIntent, defaultModel, defaultCatch, teeth, toothFilter, toothView, cumulative, sourcesWrapper, defaultConnector, connectors)) | ||
.startWith([]); | ||
if (cumulative) { | ||
spin = spin | ||
.map(spins => xs.fromArray(spins)) | ||
.compose(flattenConcurrently) | ||
.remember(); | ||
} | ||
else { | ||
spin = spin.remember(); | ||
} | ||
const sinks = teeth.reduce((accum, tooth) => { | ||
let view = spin.map(spins => xs.fromArray(spins) | ||
.map(gear => gear[tooth]) | ||
.filter(toothView => !!toothView) | ||
.compose(flattenConcurrently)) | ||
.flatten(); | ||
let view; | ||
if (cumulative) { | ||
view = spin | ||
.map((gear) => gear[tooth]) | ||
.filter(toothView => !!toothView) | ||
.compose(flattenConcurrently); | ||
} | ||
else { | ||
view = spin.map(spins => xs.fromArray(spins) | ||
.map(gear => gear[tooth]) | ||
.filter(toothView => !!toothView) | ||
.compose(flattenConcurrently)) | ||
.flatten(); | ||
} | ||
const connector = connectors.get(tooth) || defaultConnector; | ||
@@ -141,0 +158,0 @@ if (connector.fold) { |
@@ -35,2 +35,6 @@ import { Observable } from 'xstream'; | ||
export interface MotorOptions extends PedalOptions { | ||
/** | ||
* Gears are only ever added cumulatively, never removed/changed | ||
*/ | ||
cumulative?: boolean; | ||
defaultConnector?: ToothConnector<any, any, any, any>; | ||
@@ -40,2 +44,2 @@ connectors?: Map<string, ToothConnector<any, any, any, any>>; | ||
export declare function pedal(transmission: Transmission, {defaultGear, defaultFilter, sinkMap, sourcesWrapper}?: PedalOptions): (sources: any) => {}; | ||
export declare function motor(gearbox: Gearbox, {defaultGear, defaultFilter, defaultConnector, sourcesWrapper, connectors, sinkMap}?: MotorOptions): (sources: any) => {}; | ||
export declare function motor(gearbox: Gearbox, {defaultGear, defaultFilter, defaultConnector, cumulative, sourcesWrapper, connectors, sinkMap}?: MotorOptions): (sources: any) => {}; |
@@ -160,3 +160,3 @@ "use strict"; | ||
}; | ||
function spinGears(sources, defaultIntent, defaultModel, defaultCatch, teeth, toothFilter, toothView, sourcesWrapper, defaultConnector, connectors) { | ||
function spinGears(sources, defaultIntent, defaultModel, defaultCatch, teeth, toothFilter, toothView, cumulative, sourcesWrapper, defaultConnector, connectors) { | ||
var spinCache = new WeakMap(); | ||
@@ -170,3 +170,3 @@ var spinner = spinGear(sources, defaultIntent, defaultModel, defaultCatch, sourcesWrapper, teeth, toothFilter, toothView, true, defaultConnector, connectors); | ||
var cached = spinCache.get(gear); | ||
if (cached) { | ||
if (!cumulative && cached) { | ||
spins.push(cached); | ||
@@ -193,4 +193,4 @@ } | ||
function motor(gearbox, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.defaultGear, defaultGear = _c === void 0 ? { intent: function () { return ({}); }, model: function () { return xstream_1.default.of({}); }, teeth: {} } : _c, _d = _b.defaultFilter, defaultFilter = _d === void 0 ? function () { return true; } : _d, _e = _b.defaultConnector, defaultConnector = _e === void 0 ? {} : _e, _f = _b.sourcesWrapper, sourcesWrapper = _f === void 0 ? function (sources) { return sources; } : _f, _g = _b.connectors, connectors = _g === void 0 ? new Map() : _g, _h = _b.sinkMap, sinkMap = _h === void 0 ? new Map() : _h; | ||
var _j = defaultsAndHelpers(defaultGear, defaultFilter), defaultIntent = _j.defaultIntent, defaultModel = _j.defaultModel, defaultCatch = _j.defaultCatch, teeth = _j.teeth, toothFilter = _j.toothFilter, toothView = _j.toothView; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.defaultGear, defaultGear = _c === void 0 ? { intent: function () { return ({}); }, model: function () { return xstream_1.default.of({}); }, teeth: {} } : _c, _d = _b.defaultFilter, defaultFilter = _d === void 0 ? function () { return true; } : _d, _e = _b.defaultConnector, defaultConnector = _e === void 0 ? {} : _e, _f = _b.cumulative, cumulative = _f === void 0 ? false : _f, _g = _b.sourcesWrapper, sourcesWrapper = _g === void 0 ? function (sources) { return sources; } : _g, _h = _b.connectors, connectors = _h === void 0 ? new Map() : _h, _j = _b.sinkMap, sinkMap = _j === void 0 ? new Map() : _j; | ||
var _k = defaultsAndHelpers(defaultGear, defaultFilter), defaultIntent = _k.defaultIntent, defaultModel = _k.defaultModel, defaultCatch = _k.defaultCatch, teeth = _k.teeth, toothFilter = _k.toothFilter, toothView = _k.toothView; | ||
return function (sources) { | ||
@@ -205,11 +205,28 @@ var gears; | ||
var spin = xstream_1.default.fromObservable(gears) | ||
.map(spinGears(sources, defaultIntent, defaultModel, defaultCatch, teeth, toothFilter, toothView, sourcesWrapper, defaultConnector, connectors)) | ||
.startWith([]) | ||
.remember(); | ||
.map(spinGears(sources, defaultIntent, defaultModel, defaultCatch, teeth, toothFilter, toothView, cumulative, sourcesWrapper, defaultConnector, connectors)) | ||
.startWith([]); | ||
if (cumulative) { | ||
spin = spin | ||
.map(function (spins) { return xstream_1.default.fromArray(spins); }) | ||
.compose(flattenConcurrently_1.default) | ||
.remember(); | ||
} | ||
else { | ||
spin = spin.remember(); | ||
} | ||
var sinks = teeth.reduce(function (accum, tooth) { | ||
var view = spin.map(function (spins) { return xstream_1.default.fromArray(spins) | ||
.map(function (gear) { return gear[tooth]; }) | ||
.filter(function (toothView) { return !!toothView; }) | ||
.compose(flattenConcurrently_1.default); }) | ||
.flatten(); | ||
var view; | ||
if (cumulative) { | ||
view = spin | ||
.map(function (gear) { return gear[tooth]; }) | ||
.filter(function (toothView) { return !!toothView; }) | ||
.compose(flattenConcurrently_1.default); | ||
} | ||
else { | ||
view = spin.map(function (spins) { return xstream_1.default.fromArray(spins) | ||
.map(function (gear) { return gear[tooth]; }) | ||
.filter(function (toothView) { return !!toothView; }) | ||
.compose(flattenConcurrently_1.default); }) | ||
.flatten(); | ||
} | ||
var connector = connectors.get(tooth) || defaultConnector; | ||
@@ -216,0 +233,0 @@ if (connector.fold) { |
48
index.ts
@@ -47,2 +47,6 @@ import { adapt } from '@cycle/run/lib/adapt' | ||
export interface MotorOptions extends PedalOptions { | ||
/** | ||
* Gears are only ever added cumulatively, never removed/changed | ||
*/ | ||
cumulative?: boolean | ||
defaultConnector?: ToothConnector<any, any, any, any> | ||
@@ -185,2 +189,3 @@ connectors?: Map<string, ToothConnector<any, any, any, any>> | ||
toothView: (name: string, tooth: GearTooth<any> | GearView<any>) => GearView<any>, | ||
cumulative: boolean, | ||
sourcesWrapper: (sources: any, gear: Gear<any, any>) => any, | ||
@@ -205,3 +210,3 @@ defaultConnector: ToothConnector<any, any, any, any>, | ||
const cached = spinCache.get(gear) | ||
if (cached) { | ||
if (!cumulative && cached) { | ||
spins.push(cached) | ||
@@ -222,2 +227,3 @@ } else { | ||
defaultConnector = {}, | ||
cumulative = false, | ||
sourcesWrapper = (sources: any) => sources, | ||
@@ -244,13 +250,39 @@ connectors = new Map(), | ||
const spin = xs.fromObservable<Iterable<Gear<any, any>>>(gears) | ||
.map(spinGears(sources, defaultIntent, defaultModel, defaultCatch, teeth, toothFilter, toothView, sourcesWrapper, defaultConnector, connectors)) | ||
let spin = xs.fromObservable<Iterable<Gear<any, any>>>(gears) | ||
.map(spinGears(sources, | ||
defaultIntent, | ||
defaultModel, | ||
defaultCatch, | ||
teeth, | ||
toothFilter, | ||
toothView, | ||
cumulative, | ||
sourcesWrapper, | ||
defaultConnector, | ||
connectors)) | ||
.startWith([]) | ||
.remember() | ||
if (cumulative) { | ||
spin = spin | ||
.map(spins => xs.fromArray(spins)) | ||
.compose(flattenConcurrently) | ||
.remember() | ||
} else { | ||
spin = spin.remember() | ||
} | ||
const sinks = teeth.reduce((accum, tooth) => { | ||
let view = spin.map(spins => xs.fromArray(spins) | ||
.map(gear => gear[tooth]) | ||
let view: xs<any> | ||
if (cumulative) { | ||
view = spin | ||
.map((gear: any) => gear[tooth]) | ||
.filter(toothView => !!toothView) | ||
.compose(flattenConcurrently)) | ||
.flatten() | ||
.compose(flattenConcurrently) | ||
} else { | ||
view = spin.map(spins => xs.fromArray(spins) | ||
.map(gear => gear[tooth]) | ||
.filter(toothView => !!toothView) | ||
.compose(flattenConcurrently)) | ||
.flatten() | ||
} | ||
const connector = connectors.get(tooth) || defaultConnector | ||
@@ -257,0 +289,0 @@ if (connector.fold) { |
{ | ||
"name": "cycle-gear", | ||
"version": "7.1.4", | ||
"version": "7.2.0", | ||
"description": "Main function factory for CycleJS", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
71596
824