I just wanted to add some pragmatic differences from when I made the RxJS code with Redux support.
I have mapped each type of action to a Subject instance. Each state component has an object, which is then mapped to a reducer function. All reduction threads are merged with merge , and then scan displays the state. The default value is set to startWith immediately before scan . I used publishReplay(1) for states, but I could later remove it.
The real pure rendering function will consist only in the place where you create event data by sending it to all manufacturers / entities.
If you have child components, you need to describe how these states are combined into yours. combineLatest could be a good starting point for this.
Noticeable differences in implementation:
There is no middleware, only rxjs operators. I think this is the greatest strength and weakness. You can still take concepts, but it's hard for me to get help from sister communities like redux and cycle.js, as this is another specialized solution. That is why I need to write “I” instead of “we” in this text.
No switches / lines or lines for action types. You have a more dynamic way of separating actions.
rxjs can be used as a tool elsewhere and is not contained in state management.
Fewer manufacturers than action types (?). I'm not sure about this, but you can have many reactions in parent components that listen on child components. This means less imperative code and less complexity.
You have a solution. No framework is required. Good and bad. In any case, you will end up writing your own framework.
These are much more fractals, and you can easily subscribe to changes from a subtree or to several parts of the application state tree.
- Guess how easy it is to make epics, how to make reductions? Very simple.
I also work on much greater benefits when child components are described as threads. This means that we don’t need to make up the parent and child states in the reducers, since we can simply ("simply") recursively combine states based on the structure of the components.
I also think about skipping the reaction and going with a trap or something else until React handles the reactive states better. Why should we build our state up in order to break it again through props? Therefore, I will try to make version 2 of this template using Snabbdom.
Here's a more advanced but small snippet in which the state.ts file creates a state stream. This is the state of the ajax form component that receives the fields (inputs) object with validation rules and css styles. In this file, we simply use field names (object keys) to combine all child states into a form state.
export default function create({ Observable, ajaxInputs }) { const fieldStreams = Object.keys(ajaxInputs) .map(function onMap(fieldName) { return ajaxInputs[fieldName].state.stream .map(function onMap(stateData) { return {stateData, fieldName} }) }) const stateStream = Observable.combineLatest(...fieldStreams) .map(function onMap(fieldStreamDataArray) { return fieldStreamDataArray.reduce(function onReduce(acc, fieldStreamData) { acc[fieldStreamData.fieldName] = fieldStreamData.stateData return acc }, {}) }) return { stream: stateStream } }
While the code may not say much in isolation, it shows how you can build state up and how easy it is to create dynamic events. The price to pay is what you need to understand a different code style. And I like to pay this price.
Marcus Nielsen Nov 18 '16 at 10:37 2016-11-18 10:37
source share