简体   繁体   English

将ES6类与Redux一起使用

[英]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. 我想在ES6 Classes中转换那些数据,所以我可以给它们帮助方法,提供数据之间的关系,而不必一直使用普通的javascript对象。 Also, to get relations between the data, I'm having to do n-squared computations and that's slowing down the frontend. 此外,为了获得数据之间的关系,我不得不进行n平方计算,这会减慢前端的速度。

Here are the options I'm seeing: 以下是我看到的选项:

1) Create a selector that connects with the redux store. 1)创建一个与redux商店连接的选择器。 This selector could get the data from the reducer and convert it into multiple ES6 classes that I've defined. 这个选择器可以从reducer获取数据并将其转换为我定义的多个ES6类。 If the reducer gets new data that is different, then the selector will recreate the ES6 class instantiations. 如果reducer获取不同的新数据,则选择器将重新创建ES6类实例化。

2) https://github.com/tommikaikkonen/redux-orm This seems fantastic as well. 2) https://github.com/tommikaikkonen/redux-orm这看起来也很棒。

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. 3)在数据集上创建多个选择器,以计算数据集中的指定关系,因此每次我想获得一个本来是n平方计算得到的关系时,我就可以调用该选择器。

My question is which route of the three should I take? 我的问题是我应该采取哪三条路线? Is there an alternative besides these 3? 除了这3个还有其他选择吗? Or do people just work with javascript objects mostly on the frontend and not deal with ES6 classes. 或者人们只是在前端处理javascript对象而不处理ES6类。


Update: 更新:

Two months later, and I'm still using Redux-ORM in production and it is fantastic! 两个月后,我还在生产中使用终极版-ORM,它太棒了! 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 . Redux FAQ中关于规范化信息 ,我有一些关于选择器和规范化的文章作为我的React / Redux链接列表的一部分

That said, I am a huge proponent of Redux-ORM. 这就是说,我是终极版-ORM的巨大支持者。 It's a fantastic tool for helping manage normalized/relational data in your Redux store. 它是帮助管理Redux商店中的规范化/关系数据的绝佳工具。 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 . 我的实用Redux博客文章系列包括两篇专门讨论Redux-ORM的文章: Redux-ORM BasicsRedux-ORM Concepts and Techniques The latest post, Practical Redux Part 5: Loading and Displaying Data , shows Redux-ORM in action as well. 最新帖子, Practical Redux第5部分:加载和显示数据 ,也显示了Redux-ORM的运行情况。

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. Redux-ORM的作者Tommi Kaikkonen实际上刚刚对Redux-ORM进行了一次重大更新测试,改进了API和行为 ,我很期待这一点。

I definitely recommend it! 我绝对推荐它!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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