简体   繁体   中英

Using ES6 Classes with Redux

I'm working on a project that brings in a ton of data from one endpoint into aa single reducer. I'd like to convert that data in ES6 Classes, so I can give them helper method, provide relations between the data, and not have to work with plain javascript objects all the time. Also, to get relations between the data, I'm having to do n-squared computations and that's slowing down the frontend.

Here are the options I'm seeing:

1) Create a selector that connects with the redux store. This selector could get the data from the reducer and convert it into multiple ES6 classes that I've defined. If the reducer gets new data that is different, then the selector will recreate the ES6 class instantiations.

2) https://github.com/tommikaikkonen/redux-orm This seems fantastic as well.

3) Create multiple selectors on the data set to that will compute a specified relation in the data set, so I can just call that selector each time I want to get a relation that would otherwise be an n-squared computation to get.

My question is which route of the three should I take? Is there an alternative besides these 3? Or do people just work with javascript objects mostly on the frontend and not deal with ES6 classes.


Update:

Two months later, and I'm still using Redux-ORM in production and it is fantastic! Highly recommend.

It's certainly entirely possible to do all that handling with "plain" functions and selectors. There's info on normalization in the Redux FAQ , and I have some articles on selectors and normalization as part of my React/Redux links list .

That said, I am a huge proponent of Redux-ORM. It's a fantastic tool for helping manage normalized/relational data in your Redux store. I use it for normalizing nested data, querying data, and updating that data immutably.

My Practical Redux blog post series includes two articles talking about Redux-ORM specifically: Redux-ORM Basics and Redux-ORM Concepts and Techniques . The latest post, Practical Redux Part 5: Loading and Displaying Data , shows Redux-ORM in action as well.

The author of Redux-ORM, Tommi Kaikkonen, actually just put up a beta of a major update to Redux-ORM that improves the API and behavior , which I'm looking forward to playing with.

I definitely recommend it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM