Functional model vs data model and react/redux

I have a module object, that consists of several parameters and an algorithm.

A parameter consists of a min, max, step, label and value.

The module’s algorithm is regularly making a calculation based on a value on each the parameters.

In my application each of the parameters is represented by a slider on the GUI.

If you’re interested, the production version of this application is here. The code base is a mess and I’m currently tidying up.

My question is how I represent this in a react/redux architecture.

The module and its algorithm are static. But a user should be able to save the state of the application, which will likely be saved on a JSON database. At the minimum all this needs to be is simple JSON object that contains the value of each of the parameters.

So what I want to be able to do is, for each of modules, list a series of parameters that define the algorithm, and the react just for each renders each of the parameters. Simple enough.

How do I handle the differentiation between the functional model, the state we’re trying to save, which is just a few values? Should I be using my doing the algorithmic calculations as a part of the dispatch actions? Does this list of parameters come through from the redux state?

This sounds like a good use case for the Reselect helper library.

You want to keep your Redux state (and, by extension, the reducers) as simple as possible, so only include the input parameters for the calculation.

Then implement your algorithm as one or more selectors – pure functions that take the Redux state as an input and return the calculated values.

Reselect provides a method called createSelector which will automatically memoize your function – i.e. it caches the last set of input values and the result. If your selector is called again with the same inputs, then it just returns the cached result instead of repeating the calculation.

Selectors are composable – you can use the output of one selector as the input for another. Thus, by using selectors to pick out the relevant properties of the state, you can ensure that the main calculation is not repeated unnecessarily when other parts of the state are changed.

Finally, when you connect your React component to Redux, call the selectors from mapStateToProps():

function mapStateToProps(state) {
return {
fooProp: myFooSelector(state),
barProp: myBarSelector(state)
};
}

This means that the selectors get called on every render – which is OK, since they don’t do any work unless the relevant state properties have changed.

The view is now guaranteed to stay in sync with the input values, and you don’t even have to think about the circumstances when the results might change.

Even better, the algorithm is lazily evaluated – the calculation doesn’t even happen unless the user looks at a page which requires it.

0

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật