Comparing version 2.5.4 to 2.5.5
@@ -65,2 +65,5 @@ 'use strict'; | ||
}); | ||
this._linkingMiddleware.register('inject:', function (id, prop) { | ||
return prop; | ||
}); | ||
this._injectingMiddleware = new _injectingMiddleware2.default(); | ||
@@ -67,0 +70,0 @@ this._injectingMiddleware.register('events', function (obj) { |
@@ -23,2 +23,22 @@ 'use strict'; | ||
function linkProperty(copy, props, overrides, middleware, id, name) { | ||
var prop = props[name]; | ||
if (overrides) { | ||
var override = overrides[name]; | ||
if (override) { | ||
prop = override; | ||
} | ||
} | ||
if (middleware) { | ||
if (prop !== undefined) { | ||
prop = middleware(id, prop); | ||
} | ||
} | ||
if (prop !== undefined) { | ||
copy[name] = prop; | ||
} | ||
} | ||
/*****************************************************************************/ | ||
var LinkingMiddleware = (function (_Middleware) { | ||
@@ -42,3 +62,3 @@ _inherits(LinkingMiddleware, _Middleware); | ||
try { | ||
for (var _iterator = this._middlewares[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _loop = function _loop() { | ||
var item = _step.value; | ||
@@ -48,17 +68,15 @@ | ||
var middleware = item.middleware; | ||
var prop = props[name]; | ||
if (overrides) { | ||
var override = overrides[name]; | ||
if (override) { | ||
prop = override; | ||
} | ||
if (name.endsWith(':')) { | ||
Object.getOwnPropertyNames(props).filter(function (x) { | ||
return x.startsWith(name); | ||
}).forEach(function (name) { | ||
return linkProperty(copy, props, overrides, middleware, id, name); | ||
}); | ||
} else { | ||
linkProperty(copy, props, overrides, middleware, id, name); | ||
} | ||
if (middleware) { | ||
if (prop !== undefined) { | ||
prop = middleware(id, prop); | ||
} | ||
} | ||
if (prop !== undefined) { | ||
copy[name] = prop; | ||
} | ||
}; | ||
for (var _iterator = this._middlewares[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
_loop(); | ||
} | ||
@@ -65,0 +83,0 @@ } catch (err) { |
{ | ||
"name": "electrum", | ||
"version": "2.5.4", | ||
"version": "2.5.5", | ||
"description": "Electrum simplifies framework-agnostic declaration of React components.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -33,2 +33,3 @@ 'use strict'; | ||
this._linkingMiddleware.register ('theme', (id, theme) => theme); | ||
this._linkingMiddleware.register ('inject:', (id, prop) => prop); | ||
this._injectingMiddleware = new InjectingMiddleware (); | ||
@@ -35,0 +36,0 @@ this._injectingMiddleware.register ('events', obj => { |
@@ -7,2 +7,22 @@ 'use strict'; | ||
function linkProperty (copy, props, overrides, middleware, id, name) { | ||
let prop = props[name]; | ||
if (overrides) { | ||
let override = overrides[name]; | ||
if (override) { | ||
prop = override; | ||
} | ||
} | ||
if (middleware) { | ||
if (prop !== undefined) { | ||
prop = middleware (id, prop); | ||
} | ||
} | ||
if (prop !== undefined) { | ||
copy[name] = prop; | ||
} | ||
} | ||
/*****************************************************************************/ | ||
export default class LinkingMiddleware extends Middleware { | ||
@@ -14,17 +34,9 @@ link (props, id, overrides) { | ||
const middleware = item.middleware; | ||
let prop = props[name]; | ||
if (overrides) { | ||
let override = overrides[name]; | ||
if (override) { | ||
prop = override; | ||
} | ||
if (name.endsWith (':')) { | ||
Object.getOwnPropertyNames (props) | ||
.filter (x => x.startsWith (name)) | ||
.forEach (name => linkProperty (copy, props, overrides, middleware, id, name)); | ||
} else { | ||
linkProperty (copy, props, overrides, middleware, id, name); | ||
} | ||
if (middleware) { | ||
if (prop !== undefined) { | ||
prop = middleware (id, prop); | ||
} | ||
} | ||
if (prop !== undefined) { | ||
copy[name] = prop; | ||
} | ||
} | ||
@@ -31,0 +43,0 @@ return copy; |
@@ -26,3 +26,21 @@ 'use strict'; | ||
}); | ||
it ('applies default middleware logic to prefixed properties', () => { | ||
middleware.register ('foo:'); | ||
expect (middleware.link ({x: 1, 'foo:x': 'bar'}, 'i')).to.deep.equal ({'foo:x': 'bar'}); | ||
expect (middleware.link ({x: 1, 'foo:x': 'bar'}, 'i', {x: 2})).to.deep.equal ({'foo:x': 'bar'}); | ||
expect (middleware.link ({x: 1, 'foo:x': 'bar'}, 'i', {'foo:x': 'BAR'})).to.deep.equal ({'foo:x': 'BAR'}); | ||
expect (middleware.link ({x: 1, 'foo:x': 'X', 'foo:y': 'Y'}, 'i', {'foo:x': 'BAR'})) | ||
.to.deep.equal ({'foo:x': 'BAR', 'foo:y': 'Y'}); | ||
}); | ||
it ('applies custom middleware logic to prefixed properties', () => { | ||
middleware.register ('foo:', (id, prop) => prop + '/' + id); | ||
expect (middleware.link ({x: 1, 'foo:x': 'bar'}, 'i')).to.deep.equal ({'foo:x': 'bar/i'}); | ||
expect (middleware.link ({x: 1, 'foo:x': 'bar'}, 'i', {x: 2})).to.deep.equal ({'foo:x': 'bar/i'}); | ||
expect (middleware.link ({x: 1, 'foo:x': 'bar'}, 'i', {'foo:x': 'BAR'})).to.deep.equal ({'foo:x': 'BAR/i'}); | ||
expect (middleware.link ({x: 1, 'foo:x': 'X', 'foo:y': 'Y'}, 'i', {'foo:x': 'BAR'})) | ||
.to.deep.equal ({'foo:x': 'BAR/i', 'foo:y': 'Y/i'}); | ||
}); | ||
}); | ||
}); |
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
123689
2317