So, I was sooo happy when #535 was merged and with v0.35 came the possibility to register models at run time. Then I started to use this feature to be able to split my models into chunks, and import only models required by the component on screen.
Then I realized (through a bunch of nice error messages) that I use vuex-orm plugins that extend the module of entities with state, getters, mutations and actions. These plugins rely on the fact that every entity is already registered and extend modules by iterating through database.entities. Now, if I register my model in-the-fly, it won't get the module extension and will crash.
Re-reading the docs a bit I found that I could use the static state () method to add state and the static commit () method to modify it. Not my favorite, though. I find that Model.commit() is not really debug-friendly, and anyway, I would prefer to keep getters and actions too, to remain as clean in code as possible.
Another idea of mine was to extend Database from within my plugin. I could, then, extend the method register to add the required vuex-parts after executing its original task. But Database is not extendable by plugins.
Questions:
- Is it intentional that
Database is not extendable? Is it due to some security issue?
- Or, is there any other possibility to achieve my goal?
@kiaking what do you think?
Thanks in advance!
So, I was sooo happy when #535 was merged and with v0.35 came the possibility to register models at run time. Then I started to use this feature to be able to split my models into chunks, and import only models required by the component on screen.
Then I realized (through a bunch of nice error messages) that I use vuex-orm plugins that extend the module of entities with state, getters, mutations and actions. These plugins rely on the fact that every entity is already registered and extend modules by iterating through
database.entities. Now, if I register my model in-the-fly, it won't get the module extension and will crash.Re-reading the docs a bit I found that I could use the
static state ()method to add state and thestatic commit ()method to modify it. Not my favorite, though. I find thatModel.commit()is not really debug-friendly, and anyway, I would prefer to keep getters and actions too, to remain as clean in code as possible.Another idea of mine was to extend
Databasefrom within my plugin. I could, then, extend the methodregisterto add the required vuex-parts after executing its original task. ButDatabaseis not extendable by plugins.Questions:
Databaseis not extendable? Is it due to some security issue?@kiaking what do you think?
Thanks in advance!