Easy-peasy: Example for derived state with dependencies and arguments

Created on 14 May 2019  路  6Comments  路  Source: ctrlplusb/easy-peasy

Could you please provide an example of composing selectors with arguments?

const store = createStore({
  products: [{ id: 1, name: 'Shoes', price: 123 }, { id: 2, name: 'Hat', price: 75 }],

  productById: select(state =>
    id => state.products.find(x => x.id === id)
  ),

  // should be updated to use productById as a dependency
  productPrice: select(state =>
    id => '$' + state.products.find(x => x.id === id).price
  )
};
bug

Most helpful comment

FYI both - I have come up with a much better architectural design for selectors that will address your issues, and be far more performant. Plus you won't have to do this nested function based implementation which just sucks.

I am hoping to have time this weekend to be able to implement it. 馃憤

All 6 comments

This would be useful to know for me as well.

Eeek, some bugs around selectors when I tried to implement the solution. Will get back to you with an example when working.

FYI both - I have come up with a much better architectural design for selectors that will address your issues, and be far more performant. Plus you won't have to do this nested function based implementation which just sucks.

I am hoping to have time this weekend to be able to implement it. 馃憤

FYI I have published a new helper. Check out #177 for more info. I've still got loads of docs to write out. I'll be writing how to use them via Typescript too after I finish the standard JS examples.

Would really appreciate your feedback.

This is now in the next branch

FYI, there was a separate bug on selectors which has been fixed. You can call selects from each other now. 馃憤

https://codesandbox.io/s/easypeasy170-l7dle

I am still of mind to deprecate select in favour of selector - despite it being more verbose. It's still less of a footgun.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pitops picture pitops  路  4Comments

positimo picture positimo  路  3Comments

lishine picture lishine  路  6Comments

Windynik picture Windynik  路  5Comments

rankun203 picture rankun203  路  5Comments