Closed togonow closed 7 years ago
I'm using polymer 1.9 will selectors work with the same way with 0.4.2?
Selectors should work on 1.9 as they are just pure functions that accept state, this works with the statePath
function.
for some reason, selectors are not accessible from polymer elements here's the pattern i'm using: `in the store:
const store = Redux.createStore(reducer);
store.subscribe(() => {
console.log('store: ', store.getState(), store.getState().subtotal);
});
const ReduxBehavior = PolymerRedux(store);
var getItems = function getItems(state) { return state.items; };
var totalItemsSelector = Reselect.createSelector(getItems, function (getItems) {
return getItems.length;
});
in the element properties:
Polymer({ is: 'cart', behaviors: [ReduxBehavior], /jshint ignore: line / properties: { totalItemsSelector:{ type: Number, statePath: 'totalItemsSelector' } }
P.S. i'm able to pull properties from the store
statePath
looks like you're passing a string constant. You must give the actual function reference.
oops, didn't notice the difference from the other statePath. Thanks a lot, it works.
I have been using selectors in this manner. Seems to work very well.
Group them by type and import them as needed.
Add statepath to properties: static get properties() { return { summary: { type: Array, statePath: getSummaryAmounts, readOnly: true }, contracts: { type: Array, statePath: getContractAmount, readOnly: true }, selector.html:
Githubissues.
Is there a working example for using redux selector? i’m having issues adding reselect selectors to polymer 1 store