RFC: Add createComponentStore
Function
#3769
Replies: 5 comments 7 replies
-
What are the benefits in comparison to a class-based approach? |
Beta Was this translation helpful? Give feedback.
-
nice RFC. I see that you are trying to move everything to functional programming. But for this use case, I'm not seeing the benefits. I find it harder to read. With injectable class, you stay in the "angular way" of doing thing. It can be very confusing to inject a function. Will feel even more magic. |
Beta Was this translation helpful? Give feedback.
-
Looks very cool! Could it be used like so as well?
So we can have a single file feature similar to what other frameworks provide. |
Beta Was this translation helpful? Give feedback.
-
The class-based api allows for the initial state itself to be injected and/or instantiated lazily. This proposal requires the initial state as the first parameter, which seems to imply that it would have to be known statically, unless you called this function inside a provider factory of your own. I don't personally have a use case that requires this functionality, so that would be fine with me, but I noticed it. I assume it's structured this way so that the type can be inferred, which is nice. Also, I'd prefer the first return type to the alternative that returns a tuple. Getting the class or injection token or whatever it is back is more flexible, and the helper functions could always be done in userland. |
Beta Was this translation helpful? Give feedback.
-
I like it, the only nit I have is the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The
createComponentStore
function will provide the ability to create a custom ComponentStore without using a "class-based" approach. Its usage would look like this:The created ComponentStore can be used in the same way as before:
Providing at the root level
With
createComponentStore
, providing at the root level can be done as follows:Scaling
If needed, we can split ComponentStore selectors, effects, and/or updaters into separate functions, so we can avoid huge ComponentStore factories:
Benefits
ImmerComponentStore
,EntityComponentStore
, etc. However, in JS/TS, a class can only extend one class by default and without additional hacks. What if we want to create a ComponentStore that reuses entity features but also has immer updaters? 🤔 With thecreateComponentStore
function, I see the possibility of combining reusable features in a more flexible way.onStoreInit
and/oronStateInit
hooks must be provided by using theprovideComponentStore
function. This won't be necessary with thecreateComponentStore
function.Alternative
createComponentStore
signatureThere is another
createComponentStore
signature worth considering:Beta Was this translation helpful? Give feedback.
All reactions