Skip to content

Commit

Permalink
feat(statePath): Pass props to statePath
Browse files Browse the repository at this point in the history
In order to use properties in reselect, we need to pass them into the statePath.

Implements tur-nr#126
  • Loading branch information
TimPietrusky committed Feb 15, 2018
1 parent 6fb6087 commit a5f1283
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion polymer-redux.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export default function PolymerRedux(store) {

const subscribers = new Map();

function compileProps(element, properties) {
return Object.keys(properties).reduce((props, name) => Object.assign(props, {
[name]: element[name],
}), {});
}

/**
* Binds element's properties to state changes from the Redux store.
*
Expand Down Expand Up @@ -54,8 +60,9 @@ export default function PolymerRedux(store) {
let propertiesChanged = false;
bindings.forEach(name => { // Perhaps .reduce() to a boolean?
const {statePath} = properties[name];
const props = compileProps(element, properties);
const value = (typeof statePath === 'function') ?
statePath.call(element, state) :
statePath.call(element, state, props) :
get(state, statePath);

const changed = element._setPendingPropertyOrPath(name, value, true);
Expand Down

0 comments on commit a5f1283

Please sign in to comment.