From a5f12835c246e3786b52faec825fcd711bad25d5 Mon Sep 17 00:00:00 2001 From: Tim Pietrusky Date: Thu, 15 Feb 2018 06:28:15 +0100 Subject: [PATCH] feat(statePath): Pass props to statePath In order to use properties in reselect, we need to pass them into the statePath. Implements #126 --- polymer-redux.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/polymer-redux.js b/polymer-redux.js index c73aa78..3373d16 100644 --- a/polymer-redux.js +++ b/polymer-redux.js @@ -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. * @@ -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);