cycle-gear
Advanced tools
Comparing version 4.0.0 to 4.1.0
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "0.1.0", | ||
"command": "npm", | ||
"isShellCommand": true, | ||
"showOutput": "always", | ||
"suppressTaskName": true, | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"taskName": "install", | ||
"args": ["install"] | ||
}, | ||
{ | ||
"taskName": "update", | ||
"args": ["update"] | ||
}, | ||
{ | ||
"taskName": "test", | ||
"args": ["run", "test"] | ||
}, | ||
{ | ||
"taskName": "compile", | ||
"args": ["run", "compile"], | ||
"isBuildCommand": true, | ||
"problemMatcher": "$tsc" | ||
"type": "npm", | ||
"script": "compile", | ||
"problemMatcher": [ | ||
"$tsc" | ||
] | ||
} | ||
] | ||
} |
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) => xs.throw(error)); | ||
defaultIntent = defaultIntent || ((sources) => ({})); | ||
defaultModel = defaultModel || ((actions) => xs.of({})); | ||
export function pedal(transmission, { defaultGear = { intent: () => ({}), model: () => xs.of({}), teeth: {} }, defaultFilter = () => true, sinkMap = new Map() } = {}) { | ||
const defaultCatch = defaultGear.catch || ((error) => xs.throw(error)); | ||
const defaultIntent = defaultGear.intent || (() => ({})); | ||
const defaultModel = defaultGear.model || (() => xs.of({})); | ||
// Fully expand tooth defaults to avoid doing all the tests below every time | ||
const teeth = Object.keys(defaultGear.teeth); | ||
const toothDefaults = {}; | ||
const teeth = Object.keys(defaultGear.teeth || {}); | ||
const emptyTeeth = teeth.reduce((accum, cur) => Object.assign(accum, { [cur]: xs.never() }), {}); | ||
for (let tooth of teeth) { | ||
const defGearTooth = defaultGear.teeth[tooth]; | ||
if (defGearTooth instanceof Function) { | ||
toothDefaults[tooth] = { filter: defaultFilter, view: defGearTooth }; | ||
if (defaultGear.teeth) { | ||
for (let tooth of teeth) { | ||
const defGearTooth = defaultGear.teeth[tooth]; | ||
if (defGearTooth instanceof Function) { | ||
toothDefaults[tooth] = { filter: defaultFilter, view: defGearTooth }; | ||
} | ||
else { | ||
toothDefaults[tooth] = { filter: defGearTooth.filter || defaultFilter, view: defGearTooth.view }; | ||
} | ||
} | ||
else { | ||
toothDefaults[tooth] = { filter: defGearTooth.filter || defaultFilter, view: defGearTooth.view }; | ||
} | ||
} | ||
@@ -24,6 +25,6 @@ // Filter helper | ||
if (!tooth || tooth instanceof Function) { | ||
return toothDefaults[name].filter; | ||
return toothDefaults[name].filter || defaultFilter; | ||
} | ||
else { | ||
return tooth.filter || toothDefaults[name].filter; | ||
return tooth.filter || toothDefaults[name].filter || defaultFilter; | ||
} | ||
@@ -58,3 +59,3 @@ }; | ||
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])) | ||
}), {}); | ||
@@ -61,0 +62,0 @@ return views; |
@@ -6,10 +6,9 @@ "use strict"; | ||
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 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 xstream_1.default.throw(error); }); | ||
defaultIntent = defaultIntent || (function (sources) { return ({}); }); | ||
defaultModel = defaultModel || (function (actions) { return xstream_1.default.of({}); }); | ||
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.sinkMap, sinkMap = _e === void 0 ? new Map() : _e; | ||
var defaultCatch = defaultGear.catch || (function (error) { return xstream_1.default.throw(error); }); | ||
var defaultIntent = defaultGear.intent || (function () { return ({}); }); | ||
var defaultModel = defaultGear.model || (function () { return xstream_1.default.of({}); }); | ||
// Fully expand tooth defaults to avoid doing all the tests below every time | ||
var teeth = Object.keys(defaultGear.teeth); | ||
var toothDefaults = {}; | ||
var teeth = Object.keys(defaultGear.teeth || {}); | ||
var emptyTeeth = teeth.reduce(function (accum, cur) { | ||
@@ -19,11 +18,13 @@ return Object.assign(accum, (_a = {}, _a[cur] = xstream_1.default.never(), _a)); | ||
}, {}); | ||
for (var _i = 0, teeth_1 = teeth; _i < teeth_1.length; _i++) { | ||
var tooth = teeth_1[_i]; | ||
var defGearTooth = defaultGear.teeth[tooth]; | ||
if (defGearTooth instanceof Function) { | ||
toothDefaults[tooth] = { filter: defaultFilter, view: defGearTooth }; | ||
if (defaultGear.teeth) { | ||
for (var _i = 0, teeth_1 = teeth; _i < teeth_1.length; _i++) { | ||
var tooth = teeth_1[_i]; | ||
var defGearTooth = defaultGear.teeth[tooth]; | ||
if (defGearTooth instanceof Function) { | ||
toothDefaults[tooth] = { filter: defaultFilter, view: defGearTooth }; | ||
} | ||
else { | ||
toothDefaults[tooth] = { filter: defGearTooth.filter || defaultFilter, view: defGearTooth.view }; | ||
} | ||
} | ||
else { | ||
toothDefaults[tooth] = { filter: defGearTooth.filter || defaultFilter, view: defGearTooth.view }; | ||
} | ||
} | ||
@@ -33,6 +34,6 @@ // Filter helper | ||
if (!tooth || tooth instanceof Function) { | ||
return toothDefaults[name].filter; | ||
return toothDefaults[name].filter || defaultFilter; | ||
} | ||
else { | ||
return tooth.filter || toothDefaults[name].filter; | ||
return tooth.filter || toothDefaults[name].filter || defaultFilter; | ||
} | ||
@@ -68,3 +69,3 @@ }; | ||
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)); | ||
@@ -71,0 +72,0 @@ var _a; |
38
index.ts
import { adapt } from '@cycle/run/lib/adapt' | ||
import xs, { Stream, Observable } from 'xstream' | ||
import xs, { Observable } from 'xstream' | ||
@@ -33,21 +33,23 @@ export interface GearView<TModel> { | ||
export function pedal(transmission: Transmission, { | ||
defaultGear = { intent: (sources: any) => ({}), model: (actions: any) => xs.of({}), teeth: {} as GearTeeth<any> }, | ||
defaultFilter = (model: any) => true, | ||
defaultGear = { intent: () => ({}), model: () => xs.of({}), teeth: {} as GearTeeth<any> }, | ||
defaultFilter = () => true, | ||
sinkMap = new Map() | ||
}: PedalOptions = {}) { | ||
let { catch: defaultCatch, intent: defaultIntent, model: defaultModel } = defaultGear | ||
defaultCatch = defaultCatch || ((error: any) => xs.throw(error)) | ||
defaultIntent = defaultIntent || ((sources: any) => ({})) | ||
defaultModel = defaultModel || ((actions: any) => xs.of({})) | ||
const defaultCatch = defaultGear.catch || ((error: any) => xs.throw(error)) | ||
const defaultIntent = defaultGear.intent || (() => ({})) | ||
const defaultModel = defaultGear.model || (() => xs.of({})) | ||
// Fully expand tooth defaults to avoid doing all the tests below every time | ||
const teeth = Object.keys(defaultGear.teeth) | ||
const toothDefaults: { [name: string]: GearTooth<any> } = {} | ||
const teeth = Object.keys(defaultGear.teeth || {}) | ||
const emptyTeeth = teeth.reduce((accum, cur) => Object.assign(accum, { [cur]: xs.never() }), {}) | ||
for (let tooth of teeth) { | ||
const defGearTooth = defaultGear.teeth[tooth] | ||
if (defGearTooth instanceof Function) { | ||
toothDefaults[tooth] = { filter: defaultFilter, view: defGearTooth } | ||
} else { | ||
toothDefaults[tooth] = { filter: defGearTooth.filter || defaultFilter, view: defGearTooth.view } | ||
if (defaultGear.teeth) { | ||
for (let tooth of teeth) { | ||
const defGearTooth = defaultGear.teeth[tooth] | ||
if (defGearTooth instanceof Function) { | ||
toothDefaults[tooth] = { filter: defaultFilter, view: defGearTooth } | ||
} else { | ||
toothDefaults[tooth] = { filter: defGearTooth.filter || defaultFilter, view: defGearTooth.view } | ||
} | ||
} | ||
@@ -59,5 +61,5 @@ } | ||
if (!tooth || tooth instanceof Function) { | ||
return toothDefaults[name].filter | ||
return toothDefaults[name].filter || defaultFilter | ||
} else { | ||
return tooth.filter || toothDefaults[name].filter | ||
return tooth.filter || toothDefaults[name].filter || defaultFilter | ||
} | ||
@@ -92,5 +94,5 @@ } | ||
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])) | ||
}), | ||
{}) | ||
{}) | ||
@@ -97,0 +99,0 @@ return views |
{ | ||
"name": "cycle-gear", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Main function factory for CycleJS", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -5,2 +5,5 @@ { | ||
"target": "es2015", | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"moduleResolution": "node", | ||
@@ -7,0 +10,0 @@ "declaration": true, |
@@ -7,2 +7,5 @@ { | ||
"moduleResolution": "node", | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"declaration": true, | ||
@@ -9,0 +12,0 @@ "outDir": "./dist/" |
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
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
48293
341