-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution Feedback: fractal-component #45
Comments
The solution is cumbersome and breaks the open/closed principle which states:
The claim So how does it break it? If you look at the
that code would have no place being there. If the business rule changes in a significant way or if new, different business rules are added, using the current approach you would need to go back into the ToggleButton component and add code to it so it supports the new logic (add a new forwarder, possibly also new props or change the forwarder logic). The component is not closed for modification and can't really be an independent NPM module. It is too concerned with what it happening outside itself. Additionally there's the problem of modifying actions in transit. Coming from the DDD world, commands and events are immutable. You can listen to an event and publish new events or send commands as a result, but you cannot re-publish the same event with modified data. I know in the redux world there is no distinction between events and commands, but thinking in terms of events and commands can be very useful. I know that DDD and the idea of bounded contexts appeals to you because I saw how you separated public actions from private ones. In DDD, a bounded context does this separation as well and it is considered a bad practice to publish a domain event (an internal event) outside of the bounded context. The correct way is to have a translator which listens to domain events, converts the ones which are of interest to external events. These external events are what define the public interface of that bounded context and are usually in a separate repository so that the event classes can be shared between multiple consuming bounded contexts. But I digress... The solution is similar to the one I mention in the redux subspace feedback issue. You need to remove the forwarding params and the action forwarder from the
This component is clearly designed to serve just the application logic and the business rules. Publishing it as a separate NPM module is possible but most likely not of much use. OR you could just create a new |
I also have an issue with all those |
Hi @ghola, Thanks a lot for your feedback & really appreciated 😄 I think there are many ways to complete the functionality using Here, I will try my best to explain my idea around this sample app implementation and please do let me know if anything doesn't make sense~ 1> Regarding The the business rule requirement you've mentioned has been moved to scalable-frontend-with-elm-or-redux/fractal-component/src/components/Counter/index.js Lines 19 to 22 in fcde769
I have to admit that it's a wild design and not ideal. The reason why I did that probably because of the followings:
2> The same idea behinds
e.g. we can move some of the business logic to <Counter
namespacePrefix="exampleApp/Counter"
threshold="10" //--- after 10 counts increase count by `multiplier`
multiplier="2" //--- times count by 2
/> Thus, you essentially complete the business logic by 3> Regarding mutate the action in transit: I think in
Here, I think if you look at it in a more abstract way, we probably can say:
One reason we need I had the similar problem when build The sepration of public actions from private actions is actualy to solve some issues with multicast actions for 4> I am actually quite interested in the new component design that you've mentioned but hard to visualise it without seeing some code. Are you able to provide some sample code of your design? Many Thanks~ 😄 |
Hey @t83714, thanks for the reply. Your arguments make sense, but I disagree with some of them. In the end it's a balance between the type of compromises you are willing to make. I don't believe configuration over glue code is a winning strategy on the long term. It's too idealized to be viable in the real world. To make configuration work you need to author really smart components, and the smarter they are, the more dead weight they carry. They either become too abstract and generic which make them hard to understand, or they become packed with too many concrete features which only a few will make use of. I will provide a MR with the component design I was mentioning above and then I will also post new business rules to be implemented 😄. Then we'll see how the two approaches are able to accommodate them and how many changes each of them needs to make (especially in the components which are publishable as NPM modules). |
Has submitted my solution via #44
Created this issue to make it easier for anyone who wants to check it out.
The problem of building a scalable frontend application using Redux or Elm has been well described by @slorber here
fractal-component
perfectly solved this problem by providing a fully decoupled component encapsulation mechanism --- a component created usingfractal-component
can be even published as NPM modules while still enjoy the convenience of predictable global Redux store.You can actually have a look at the NPM module version of this example on CodePen --- see how whole example App's logic is implemented in a single HTML file by pulling UMD version of NPM modules from CDN :-)
How
fractal-component
achieves that? It powers your components with the following features:Multicast
ActionsHot Plug
Redux Reducer & Auto mount / unmountHot Plug
Saga & Auto mount / unmountA typical structure of components created by
fractal-component
can be illustrated by the graph below:Run example App locally
Then, visit
http://localhost:3000/
Giphy.com API key
The exampleApp comes with a testing Giphy.com API key in order to retrieve random Gifs from https://giphy.com/. The api key is limted to 40 requests per hour.
You can create your own API key from https://developers.giphy.com/ and replace the API key in Component RandomGif
The text was updated successfully, but these errors were encountered: