cycle-gear
Advanced tools
Comparing version 3.1.0 to 4.0.0-alpha.1
@@ -1,2 +0,2 @@ | ||
import * as Rx from 'rx'; | ||
import { Stream } from 'xstream'; | ||
export interface GearView<TModel> { | ||
@@ -13,8 +13,8 @@ (model: TModel): any; | ||
export interface Gear<TActions, TModel> { | ||
catch?: (error: any, actions: TActions) => Rx.Observable<any>; | ||
catch?: (error: any, actions: TActions) => Stream<any>; | ||
intent?: (sources: any) => TActions; | ||
model?: (actions: TActions) => Rx.Observable<TModel>; | ||
model?: (actions: TActions) => Stream<TModel>; | ||
teeth?: GearTeeth<TModel>; | ||
} | ||
export declare type Transmission = ((sources: any) => Rx.Observable<Gear<any, any>>) | Rx.Observable<Gear<any, any>>; | ||
export declare type Transmission = ((sources: any) => Stream<Gear<any, any>>) | Stream<Gear<any, any>>; | ||
export interface PedalOptions { | ||
@@ -21,0 +21,0 @@ defaultGear?: Gear<any, any>; |
@@ -1,11 +0,12 @@ | ||
import * as Rx from 'rx'; | ||
export function pedal(transmission, { defaultGear = { intent: (sources) => ({}), model: (actions) => Rx.Observable.just({}), teeth: {} }, defaultFilter = (model) => true, sinkMap = new Map() } = {}) { | ||
import { adapt } from '@cycle/run/lib/adapt'; | ||
import xs from 'xstream'; | ||
export function pedal(transmission, { defaultGear = { intent: (sources) => ({}), model: (actions) => xs.of({}), teeth: {} }, defaultFilter = (model) => true, sinkMap = new Map() } = {}) { | ||
let { catch: defaultCatch, intent: defaultIntent, model: defaultModel } = defaultGear; | ||
defaultCatch = defaultCatch || ((error) => Rx.Observable.throw(error)); | ||
defaultCatch = defaultCatch || ((error) => xs.throw(error)); | ||
defaultIntent = defaultIntent || ((sources) => ({})); | ||
defaultModel = defaultModel || ((actions) => Rx.Observable.just({}).delay(300)); // TODO: Why does this delay work? | ||
defaultModel = defaultModel || ((actions) => xs.of({})); | ||
// Fully expand tooth defaults to avoid doing all the tests below every time | ||
const teeth = Object.keys(defaultGear.teeth); | ||
const toothDefaults = {}; | ||
const emptyTeeth = teeth.reduce((accum, cur) => Object.assign(accum, { [cur]: Rx.Observable.never() }), {}); | ||
const emptyTeeth = teeth.reduce((accum, cur) => Object.assign(accum, { [cur]: xs.never() }), {}); | ||
for (let tooth of teeth) { | ||
@@ -42,21 +43,23 @@ const defGearTooth = defaultGear.teeth[tooth]; | ||
return (sources) => { | ||
let gear$; | ||
let gear; | ||
if (transmission instanceof Function) { | ||
gear$ = transmission(sources); | ||
gear = transmission(sources); | ||
} | ||
else { | ||
gear$ = transmission; | ||
gear = transmission; | ||
} | ||
const spin$ = gear$.map(gear => { | ||
const spin = gear.map(gear => { | ||
const actions = gear.intent ? gear.intent(sources) : defaultIntent(sources); | ||
const state$ = (gear.model ? gear.model(actions) : defaultModel(actions)) | ||
.catch((err) => gear.catch ? gear.catch(err, actions) : defaultCatch(err, actions)) | ||
.shareReplay(1); | ||
const state = (gear.model ? gear.model(actions) : defaultModel(actions)) | ||
.replaceError((err) => gear.catch ? gear.catch(err, actions) : defaultCatch(err, actions)) | ||
.remember(); | ||
const views = teeth.reduce((accum, tooth) => Object.assign(accum, { | ||
[tooth]: state$.filter(toothFilter(tooth, gear.teeth[tooth])).map(toothView(tooth, gear.teeth[tooth])) | ||
[tooth]: state.filter(toothFilter(tooth, gear.teeth[tooth])).map(toothView(tooth, gear.teeth[tooth])) | ||
}), {}); | ||
return views; | ||
}).shareValue(emptyTeeth); | ||
}) | ||
.startWith(emptyTeeth) | ||
.remember(); | ||
const sinks = teeth.reduce((accum, tooth) => Object.assign(accum, { | ||
[sinkMap.has(tooth) ? sinkMap.get(tooth) : tooth]: spin$.flatMapLatest((views) => views[tooth]) | ||
[sinkMap.has(tooth) ? sinkMap.get(tooth) : tooth]: adapt(spin.map((views) => views[tooth]).flatten()) | ||
}), {}); | ||
@@ -63,0 +66,0 @@ return sinks; |
@@ -1,2 +0,2 @@ | ||
import * as Rx from 'rx'; | ||
import { Stream } from 'xstream'; | ||
export interface GearView<TModel> { | ||
@@ -13,8 +13,8 @@ (model: TModel): any; | ||
export interface Gear<TActions, TModel> { | ||
catch?: (error: any, actions: TActions) => Rx.Observable<any>; | ||
catch?: (error: any, actions: TActions) => Stream<any>; | ||
intent?: (sources: any) => TActions; | ||
model?: (actions: TActions) => Rx.Observable<TModel>; | ||
model?: (actions: TActions) => Stream<TModel>; | ||
teeth?: GearTeeth<TModel>; | ||
} | ||
export declare type Transmission = ((sources: any) => Rx.Observable<Gear<any, any>>) | Rx.Observable<Gear<any, any>>; | ||
export declare type Transmission = ((sources: any) => Stream<Gear<any, any>>) | Stream<Gear<any, any>>; | ||
export interface PedalOptions { | ||
@@ -21,0 +21,0 @@ defaultGear?: Gear<any, any>; |
"use strict"; | ||
var Rx = require("rx"); | ||
var adapt_1 = require("@cycle/run/lib/adapt"); | ||
var xstream_1 = require("xstream"); | ||
function pedal(transmission, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.defaultGear, defaultGear = _c === void 0 ? { intent: function (sources) { return ({}); }, model: function (actions) { return Rx.Observable.just({}); }, teeth: {} } : _c, _d = _b.defaultFilter, defaultFilter = _d === void 0 ? function (model) { return true; } : _d, _e = _b.sinkMap, sinkMap = _e === void 0 ? new Map() : _e; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.defaultGear, defaultGear = _c === void 0 ? { intent: function (sources) { return ({}); }, model: function (actions) { return xstream_1.default.of({}); }, teeth: {} } : _c, _d = _b.defaultFilter, defaultFilter = _d === void 0 ? function (model) { return true; } : _d, _e = _b.sinkMap, sinkMap = _e === void 0 ? new Map() : _e; | ||
var defaultCatch = defaultGear.catch, defaultIntent = defaultGear.intent, defaultModel = defaultGear.model; | ||
defaultCatch = defaultCatch || (function (error) { return Rx.Observable.throw(error); }); | ||
defaultCatch = defaultCatch || (function (error) { return xstream_1.default.throw(error); }); | ||
defaultIntent = defaultIntent || (function (sources) { return ({}); }); | ||
defaultModel = defaultModel || (function (actions) { return Rx.Observable.just({}).delay(300); }); // TODO: Why does this delay work? | ||
defaultModel = defaultModel || (function (actions) { return xstream_1.default.of({}); }); | ||
// Fully expand tooth defaults to avoid doing all the tests below every time | ||
@@ -13,3 +14,3 @@ var teeth = Object.keys(defaultGear.teeth); | ||
var emptyTeeth = teeth.reduce(function (accum, cur) { | ||
return Object.assign(accum, (_a = {}, _a[cur] = Rx.Observable.never(), _a)); | ||
return Object.assign(accum, (_a = {}, _a[cur] = xstream_1.default.never(), _a)); | ||
var _a; | ||
@@ -49,17 +50,17 @@ }, {}); | ||
return function (sources) { | ||
var gear$; | ||
var gear; | ||
if (transmission instanceof Function) { | ||
gear$ = transmission(sources); | ||
gear = transmission(sources); | ||
} | ||
else { | ||
gear$ = transmission; | ||
gear = transmission; | ||
} | ||
var spin$ = gear$.map(function (gear) { | ||
var spin = gear.map(function (gear) { | ||
var actions = gear.intent ? gear.intent(sources) : defaultIntent(sources); | ||
var state$ = (gear.model ? gear.model(actions) : defaultModel(actions)) | ||
.catch(function (err) { return gear.catch ? gear.catch(err, actions) : defaultCatch(err, actions); }) | ||
.shareReplay(1); | ||
var state = (gear.model ? gear.model(actions) : defaultModel(actions)) | ||
.replaceError(function (err) { return gear.catch ? gear.catch(err, actions) : defaultCatch(err, actions); }) | ||
.remember(); | ||
var views = teeth.reduce(function (accum, tooth) { | ||
return Object.assign(accum, (_a = {}, | ||
_a[tooth] = state$.filter(toothFilter(tooth, gear.teeth[tooth])).map(toothView(tooth, gear.teeth[tooth])), | ||
_a[tooth] = state.filter(toothFilter(tooth, gear.teeth[tooth])).map(toothView(tooth, gear.teeth[tooth])), | ||
_a)); | ||
@@ -69,6 +70,8 @@ var _a; | ||
return views; | ||
}).shareValue(emptyTeeth); | ||
}) | ||
.startWith(emptyTeeth) | ||
.remember(); | ||
var sinks = teeth.reduce(function (accum, tooth) { | ||
return Object.assign(accum, (_a = {}, | ||
_a[sinkMap.has(tooth) ? sinkMap.get(tooth) : tooth] = spin$.flatMapLatest(function (views) { return views[tooth]; }), | ||
_a[sinkMap.has(tooth) ? sinkMap.get(tooth) : tooth] = adapt_1.adapt(spin.map(function (views) { return views[tooth]; }).flatten()), | ||
_a)); | ||
@@ -75,0 +78,0 @@ var _a; |
45
index.ts
@@ -1,2 +0,3 @@ | ||
import * as Rx from 'rx' | ||
import { adapt } from '@cycle/run/lib/adapt' | ||
import xs, { Stream } from 'xstream' | ||
@@ -17,9 +18,9 @@ export interface GearView<TModel> { | ||
export interface Gear<TActions, TModel> { | ||
catch?: (error: any, actions: TActions) => Rx.Observable<any> | ||
catch?: (error: any, actions: TActions) => Stream<any> | ||
intent?: (sources: any) => TActions | ||
model?: (actions: TActions) => Rx.Observable<TModel> | ||
model?: (actions: TActions) => Stream<TModel> | ||
teeth?: GearTeeth<TModel> | ||
} | ||
export type Transmission = ((sources: any) => Rx.Observable<Gear<any, any>>) | Rx.Observable<Gear<any, any>> | ||
export type Transmission = ((sources: any) => Stream<Gear<any, any>>) | Stream<Gear<any, any>> | ||
@@ -33,3 +34,3 @@ export interface PedalOptions { | ||
export function pedal(transmission: Transmission, { | ||
defaultGear = { intent: (sources: any) => ({}), model: (actions: any) => Rx.Observable.just({}), teeth: {} as GearTeeth<any> }, | ||
defaultGear = { intent: (sources: any) => ({}), model: (actions: any) => xs.of({}), teeth: {} as GearTeeth<any> }, | ||
defaultFilter = (model: any) => true, | ||
@@ -39,5 +40,5 @@ sinkMap = new Map() | ||
let { catch: defaultCatch, intent: defaultIntent, model: defaultModel } = defaultGear | ||
defaultCatch = defaultCatch || ((error: any) => Rx.Observable.throw(error)) | ||
defaultCatch = defaultCatch || ((error: any) => xs.throw(error)) | ||
defaultIntent = defaultIntent || ((sources: any) => ({})) | ||
defaultModel = defaultModel || ((actions: any) => Rx.Observable.just({}).delay(300)) // TODO: Why does this delay work? | ||
defaultModel = defaultModel || ((actions: any) => xs.of({})) | ||
@@ -47,3 +48,3 @@ // Fully expand tooth defaults to avoid doing all the tests below every time | ||
const toothDefaults: { [name: string]: GearTooth<any> } = {} | ||
const emptyTeeth = teeth.reduce((accum, cur) => Object.assign(accum, { [cur]: Rx.Observable.never() }), {}) | ||
const emptyTeeth = teeth.reduce((accum, cur) => Object.assign(accum, { [cur]: xs.never() }), {}) | ||
for (let tooth of teeth) { | ||
@@ -54,3 +55,3 @@ const defGearTooth = defaultGear.teeth[tooth] | ||
} else { | ||
toothDefaults[tooth] = { filter: (defGearTooth as GearTooth<any>).filter || defaultFilter, view: (defGearTooth as GearTooth<any>).view } | ||
toothDefaults[tooth] = { filter: defGearTooth.filter || defaultFilter, view: defGearTooth.view } | ||
} | ||
@@ -64,3 +65,3 @@ } | ||
} else { | ||
return (tooth as GearTooth<any>).filter || toothDefaults[name].filter | ||
return tooth.filter || toothDefaults[name].filter | ||
} | ||
@@ -76,3 +77,3 @@ } | ||
} else { | ||
return (tooth as GearTooth<any>).view | ||
return tooth.view | ||
} | ||
@@ -82,16 +83,16 @@ } | ||
return (sources: any) => { | ||
let gear$: Rx.Observable<Gear<any, any>> | ||
let gear: Stream<Gear<any, any>> | ||
if (transmission instanceof Function) { | ||
gear$ = transmission(sources) | ||
gear = transmission(sources) | ||
} else { | ||
gear$ = transmission as Rx.Observable<Gear<any, any>> | ||
gear = transmission | ||
} | ||
const spin$ = gear$.map(gear => { | ||
const spin = gear.map(gear => { | ||
const actions = gear.intent ? gear.intent(sources) : defaultIntent(sources) | ||
const state$ = (gear.model ? gear.model(actions) : defaultModel(actions)) | ||
.catch((err: any) => gear.catch ? gear.catch(err, actions) : defaultCatch(err, actions)) | ||
.shareReplay(1) | ||
const state = (gear.model ? gear.model(actions) : defaultModel(actions)) | ||
.replaceError((err: any) => gear.catch ? gear.catch(err, actions) : defaultCatch(err, actions)) | ||
.remember() | ||
const views = teeth.reduce((accum, tooth) => Object.assign(accum, { | ||
[tooth]: state$.filter(toothFilter(tooth, gear.teeth[tooth])).map(toothView(tooth, gear.teeth[tooth])) | ||
[tooth]: state.filter(toothFilter(tooth, gear.teeth[tooth])).map(toothView(tooth, gear.teeth[tooth])) | ||
}), | ||
@@ -101,6 +102,8 @@ {}) | ||
return views | ||
}).shareValue(emptyTeeth) | ||
}) | ||
.startWith(emptyTeeth) | ||
.remember() | ||
const sinks = teeth.reduce((accum, tooth) => Object.assign(accum, { | ||
[sinkMap.has(tooth) ? sinkMap.get(tooth) : tooth]: spin$.flatMapLatest((views: any) => views[tooth]) | ||
[sinkMap.has(tooth) ? sinkMap.get(tooth) : tooth]: adapt(spin.map((views: any) => views[tooth]).flatten()) | ||
}), | ||
@@ -107,0 +110,0 @@ {}) |
{ | ||
"name": "cycle-gear", | ||
"version": "3.1.0", | ||
"version": "4.0.0-alpha.1", | ||
"description": "Main function factory for CycleJS", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -5,2 +5,3 @@ { | ||
"target": "es2015", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
@@ -10,5 +11,4 @@ "outDir": "./dist-es2015/" | ||
"files": [ | ||
"index.ts", | ||
"typings/index.d.ts" | ||
"index.ts" | ||
] | ||
} |
@@ -6,2 +6,3 @@ { | ||
"noLib": true, | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
@@ -12,5 +13,4 @@ "outDir": "./dist/" | ||
"index.ts", | ||
"node_modules/typescript/lib/lib.es6.d.ts", | ||
"typings/index.d.ts" | ||
"node_modules/typescript/lib/lib.es6.d.ts" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47956
15
343
2