Comparing version 2.5.5 to 2.6.0
@@ -25,7 +25,4 @@ 'use strict'; | ||
var prop = props[name]; | ||
if (overrides) { | ||
var override = overrides[name]; | ||
if (override) { | ||
prop = override; | ||
} | ||
if (overrides.hasOwnProperty(name)) { | ||
prop = overrides[name]; | ||
} | ||
@@ -37,3 +34,5 @@ if (middleware) { | ||
} | ||
if (prop !== undefined) { | ||
if (prop === undefined) { | ||
delete copy[name]; | ||
} else { | ||
copy[name] = prop; | ||
@@ -56,3 +55,5 @@ } | ||
key: 'link', | ||
value: function link(props, id, overrides) { | ||
value: function link(props, id) { | ||
var overrides = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var copy = {}; | ||
@@ -70,5 +71,10 @@ var _iteratorNormalCompletion = true; | ||
if (name.endsWith(':')) { | ||
Object.getOwnPropertyNames(props).filter(function (x) { | ||
var n1 = Object.getOwnPropertyNames(props).filter(function (x) { | ||
return x.startsWith(name); | ||
}).forEach(function (name) { | ||
}); | ||
var n2 = Object.getOwnPropertyNames(overrides).filter(function (x) { | ||
return x.startsWith(name); | ||
}); | ||
var names = new Set(n1.concat(n2)); | ||
names.forEach(function (name) { | ||
return linkProperty(copy, props, overrides, middleware, id, name); | ||
@@ -75,0 +81,0 @@ }); |
@@ -65,2 +65,8 @@ 'use strict'; | ||
}, { | ||
key: 'resolveStyle', | ||
value: function resolveStyle(name) { | ||
var styles = stylesResolver(this.theme); | ||
return styles.resolve(name); | ||
} | ||
}, { | ||
key: 'theme', | ||
@@ -67,0 +73,0 @@ get: function get() { |
{ | ||
"name": "electrum", | ||
"version": "2.5.5", | ||
"version": "2.6.0", | ||
"description": "Electrum simplifies framework-agnostic declaration of React components.", | ||
@@ -34,3 +34,3 @@ "main": "lib/index.js", | ||
"electrum-store": "^1.2.0", | ||
"electrum-theme": "^1.2.0", | ||
"electrum-theme": "^1.3.0", | ||
"electrum-utils": "^1.0.0" | ||
@@ -37,0 +37,0 @@ }, |
@@ -9,7 +9,4 @@ 'use strict'; | ||
let prop = props[name]; | ||
if (overrides) { | ||
let override = overrides[name]; | ||
if (override) { | ||
prop = override; | ||
} | ||
if (overrides.hasOwnProperty (name)) { | ||
prop = overrides[name]; | ||
} | ||
@@ -21,3 +18,5 @@ if (middleware) { | ||
} | ||
if (prop !== undefined) { | ||
if (prop === undefined) { | ||
delete copy[name]; | ||
} else { | ||
copy[name] = prop; | ||
@@ -30,3 +29,3 @@ } | ||
export default class LinkingMiddleware extends Middleware { | ||
link (props, id, overrides) { | ||
link (props, id, overrides = {}) { | ||
let copy = {}; | ||
@@ -37,5 +36,6 @@ for (let item of this._middlewares) { | ||
if (name.endsWith (':')) { | ||
Object.getOwnPropertyNames (props) | ||
.filter (x => x.startsWith (name)) | ||
.forEach (name => linkProperty (copy, props, overrides, middleware, id, name)); | ||
const n1 = Object.getOwnPropertyNames (props).filter (x => x.startsWith (name)); | ||
const n2 = Object.getOwnPropertyNames (overrides).filter (x => x.startsWith (name)); | ||
const names = new Set (n1.concat (n2)); | ||
names.forEach (name => linkProperty (copy, props, overrides, middleware, id, name)); | ||
} else { | ||
@@ -42,0 +42,0 @@ linkProperty (copy, props, overrides, middleware, id, name); |
@@ -44,3 +44,24 @@ 'use strict'; | ||
}); | ||
it ('overrides missing properties', () => { | ||
middleware.register ('foo', (id, prop) => prop + '/' + id); | ||
expect (middleware.link ({x: 1, foo: 'bar'}, 'i')).to.deep.equal ({foo: 'bar/i'}); | ||
expect (middleware.link ({x: 1, foo: 'bar'}, 'i', {foo: 'foo'})).to.deep.equal ({foo: 'foo/i'}); | ||
expect (middleware.link ({x: 1, bar: 'bar'}, 'i', {foo: 'foo'})).to.deep.equal ({foo: 'foo/i'}); | ||
}); | ||
it ('overrides missing 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', {'foo:x': 'foo'})).to.deep.equal ({'foo:x': 'foo/i'}); | ||
expect (middleware.link ({x: 1, 'foo:x': 'bar'}, 'i', {'foo:y': 'foo'})) | ||
.to.deep.equal ({'foo:x': 'bar/i', 'foo:y': 'foo/i'}); | ||
}); | ||
it ('removes property when overrides specify an undefined value', () => { | ||
middleware.register ('foo', (id, prop) => prop + '/' + id); | ||
expect (middleware.link ({x: 1, foo: 'bar'}, 'i')).to.deep.equal ({foo: 'bar/i'}); | ||
expect (middleware.link ({x: 1, foo: 'bar'}, 'i', {foo: undefined})).to.deep.equal ({}); | ||
}); | ||
}); | ||
}); |
@@ -54,3 +54,3 @@ 'use strict'; | ||
describe ('Store.link() using LinkingMiddleware', () => { | ||
describe ('Electrum.link() using LinkingMiddleware', () => { | ||
it ('produces properties linked to child state', () => { | ||
@@ -96,3 +96,15 @@ const store = Store.create ('x'); | ||
}); | ||
it ('produces properties including "inject:.." properties', () => { | ||
const store = Store.create ('x'); | ||
const theme = Theme.create ('default'); | ||
store.select ('a.b.c'); | ||
const props1 = {state: store.find ('a'), theme: theme, 'inject:x': 'X', 'inject:y': 'Y'}; | ||
const props2 = Electrum.link (props1, 'b', {'inject:x': '?'}); | ||
expect (props1.theme).to.equal (theme); | ||
expect (props2.theme).to.equal (theme); | ||
expect (props2).to.have.property ('inject:x', '?'); | ||
expect (props2).to.have.property ('inject:y', 'Y'); | ||
}); | ||
}); | ||
}); |
@@ -35,2 +35,6 @@ 'use strict'; | ||
} | ||
resolveStyle (name) { | ||
const styles = stylesResolver (this.theme); | ||
return styles.resolve (name); | ||
} | ||
get styles () { | ||
@@ -37,0 +41,0 @@ const styles = stylesResolver (this.theme); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
126238
2361
Updatedelectrum-theme@^1.3.0