-
Notifications
You must be signed in to change notification settings - Fork 55
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
Extend Store functionality #40
Comments
I did this recently albeit not as elegantly as I would have liked. Here's the code. It works great, however, typing everything is pretty horrible
Here are some of the generic types. I had to create
...and here is the extended store code...
|
We have successfully used instances of the same store to share a functionality between different places without the need for "extending" a store, many times. I think extending a store is fundamentally against how react-sweet-state is constructed; i.e it will look more like a "mixin" as there won't be any straightforward way to set explicit state/function overrides without significant changes to the library.
I think current ability to share actions and container instances (via scopes) is a pretty powerful tool that does not need an extra layer of store extension rules. It already provides a tool for combining different stores and behaviours via React's well accepted composition tools. On the other hand the current system is not perfect and sharing the behaviour and data is not straightforward. But there are solutions to the problem without breaking the "compositional" structure. See #146 if you want to provide support for improving the way it works 😊 |
Background
As we discussed in SweetState brownbag session, I was wondering if it makes sense to add a function to extend an existing store.
The idea is that I really like sweet state that store is going to be light-weighted, but in the other side, there could be multiple stores with very similar shape. For example, we might have many different modals. We might want to have a mother store shape with mother actions. In different modals, we can extend this store.
I see benefits of extending an existing Store:
What I imagine is something like this, but, of course, could be different.
createExtendedStore(Store, {initialState, actions, name});
initialState and actions will accept only additional ones. If an existing property is given to initialState, initial state will be overrided.
Need further discussion for items:
IMHO,
What do you think?
The text was updated successfully, but these errors were encountered: