-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass properties to reselect selector in statePath #126
Comments
So what I tried instead was overwriting the class TimelineScene extends ReduxMixin(PolymerElement) {
static get properties() {
return {
scene: Object,
sceneAnimations: {
type: Array,
statePath(state) {
// getAnimations is a selector
return getAnimations(state).filter(animation => {
return this.scene.animations.includes(animation.id)
})
}
}
}
} That works, but also gets executed every time something in the state is changing (and that might be something completely different than the data I access here). So doing it like this is too expensive in terms of performance. |
Hey, yes it would be a nice addition to pass the properties to reselect. So let's discuss implementation; // ./polymer-redux.js
function compileProps(element, properties) {
return Object.keys(properties).reduce((props, name) => Object.assign(props, {
[name]: element[name],
}), {});
}
// ...
const props = compileProps(element, properties);
const value = (typeof statePath === 'function') ?
statePath.call(element, state, props) :
get(state, statePath); Thoughts? |
This looks good to me right now and I the only "side effect" I can think of would be, that also every property that is created out of the Update 1I added your implementation to my local Update 2When using the Update 3I'm using reselect now as asked in my initial comment and it's working: I can access & use the properties of the component. Update 4I still have the same "problem" as in #126 (comment): When having more than 1 element in the selector, the |
In order to use properties in reselect, we need to pass them into the statePath. Implements tur-nr#126
I'm using reselect to create a selector and use that selector in my component as the
statePath
. This is working fine when I can access all my data in the state.But what if I want to use some properties from the component that need to be passed into the selector, so that it can select a specific element from the state (when the state is an array of objects and I need to select the data of a specific element in the array).
According to the documentation for reselect, you can access properties in selectors by passing them into the selector, but how can this be achieved when using the selector as the
statePath
?Additional info
I'm on the https://github.com/tur-nr/polymer-redux/tree/polymer-3 branch
The text was updated successfully, but these errors were encountered: