Easy-peasy: addModel resets store to default state

Created on 22 May 2019  路  14Comments  路  Source: ctrlplusb/easy-peasy

Hello,

I'm working on an app where I need to split everything into modules, and therefore split the store into different chunks too.

I saw the functionality for store.addModel, but I might be missing something as it resets the store to the initialState when used. I would expect it to keep whatever state exists, but inject the model I'm passing dynamically, ready to be used from that point onwards.

Steps to reproduce:

  1. Dispatch any action to update a value in the store
  2. Call store.addModel('test', { newModel: true })
  3. Observe how the value changed in point 1. has now reverted to default
bug

Most helpful comment

Fixed in [email protected] 馃憤

All 14 comments

Hey @dai4

Thanks for raising this. Will look into it.

The work I am doing on #131 actually raises some interesting primitives and opportunities to dynamically load stores. I have some really interesting ideas around this which I am excited to share.

Thanks @ctrlplusb !
Are you planning on including these changes in the 2.3.0 release?

Yep 馃憤

Hi @ctrlplusb,

I had a look at your PR related to #131 and I think that functionality wouldn't actually fix the issue in this thread. It looks good as a pattern and definitely useful, but dynamically loaded store chunks are sort of separate. From the way I understand it so far, local stores can be accessed via Component.useStore | Component.useActions etc, but a dynamically loaded store chunk would actually allow one to just useStore as usual, without specifying a component. What are your thoughts on this?

Similar issue of mine #180
To my liking, ideally I would be able to create store part everywhere, but it can be dynamically added to global store.
So I can access global store in the business logic and in the view.
I can create sub-store from the business logic and in the view.
Then, for example, my form data will be in the global store, but will be accessible locally through a path.
This is the way I have seen it done in Re-frame.

This is next on my hit list. 馃憤

Fixed in [email protected] 馃憤

Brilliant! Thanks!

FYI, updated docs on the addModel and removeModel APIs are coming within the next minor release (v2.4.0 - currently)

Great, I'll wait for that! The typescript types seem to be missing too.

FYI, the changes you merged to 2.3.2 don't include the compiled dist folder.

Ah dang, missed the types too. Will sort that.

The dist folder is available on the latest publish:

https://unpkg.io/[email protected]/dist/

Thanks for the types!

What I meant about the dist folder is that your changes are not compiled in there. It still shows the old version of the code. I think your husky prepublish script failed somehow and it didn't push the latest compiled code.

AH! That sounds like a nasty bug. Thanks for pointing this out dude. 鉂わ笍鉂わ笍鉂わ笍

Released new version 馃憤

Was this page helpful?
0 / 5 - 0 ratings