tur-nr / polymer-redux

Polymer bindings for Redux.
https://tur-nr.github.io/polymer-redux
MIT License
440 stars 67 forks source link

redux selector #88

Closed togonow closed 7 years ago

togonow commented 7 years ago

Is there a working example for using redux selector? i’m having issues adding reselect selectors to polymer 1 store

tur-nr commented 7 years ago

https://github.com/tur-nr/polymer-redux/blob/develop/v0/demo/selectors.html

togonow commented 7 years ago

I'm using polymer 1.9 will selectors work with the same way with 0.4.2?

tur-nr commented 7 years ago

Selectors should work on 1.9 as they are just pure functions that accept state, this works with the statePath function.

togonow commented 7 years ago

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

tur-nr commented 7 years ago

statePath looks like you're passing a string constant. You must give the actual function reference.

togonow commented 7 years ago

oops, didn't notice the difference from the other statePath. Thanks a lot, it works.

rkief commented 7 years ago

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.
  • Githubissues is a development platform for aggregating issues.