Skip to content

register model at runtime#511

Closed
SzNagyMisu wants to merge 5 commits into
vuex-orm:masterfrom
SzNagyMisu:187-register-model-at-runtime
Closed

register model at runtime#511
SzNagyMisu wants to merge 5 commits into
vuex-orm:masterfrom
SzNagyMisu:187-register-model-at-runtime

Conversation

@SzNagyMisu

Copy link
Copy Markdown

PR for #187

90% done - stuck with remaining 10%...

I can register a brand new module into vuex (like 'entities/hobbies') but cannot add a new getter under an existing module (like the namespaced getter 'hobbies' under the module 'entities').

See L44-L46 in ModuleBuilder.createModules()

static createModules (tree: Module, namespace: string, models: Models, modules: Modules): Module {
Object.keys(modules).forEach((name) => {
const model = models[name]
const module = modules[name]
tree.modules[name] = { namespaced: true }
tree.modules[name].state = this.createState(namespace, name, model, module)
tree.getters[name] = (_state: RootState, getters: any, _rootState: any, _rootGetters: any) => () => {
return getters.query(name)
}
tree.modules[name].getters = { ...Getters, ...module.getters }
tree.modules[name].actions = { ...Actions, ...module.actions }
tree.modules[name].mutations = module.mutations || {}
})
return tree
}

Any ideas?
@kiaking what are that gettters for? I don't remember having met them in the docs or during coding.

Szijjártó-Nagy Misu added 2 commits December 2, 2019 13:39
@kiaking

kiaking commented Dec 3, 2019

Copy link
Copy Markdown
Member

Ahh... yeah. That getter is so we can do store.getters['entities/users']() and get Query instance of User model. It's shortcut for store.getters['entities/users/query']().

Looking into Vuex doc, maybe there's no way to add extra getters after store initialization... As you mentioned, it's not documented so maybe we can just remove that functionality.

Do you think you can remove the test for that getter and make this PR pass?

Thank you so much for the PR by the way! 🎉

@kiaking kiaking added the enhancement New feature or request label Dec 3, 2019
  removed shorthand store.getters['entities/users']()
  for accessing query object of the model
  use the long version instead: store.getters['entities/users/query']()
@codecov

codecov Bot commented Dec 3, 2019

Copy link
Copy Markdown

Codecov Report

Merging #511 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #511   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          47     47           
  Lines        1798   1812   +14     
  Branches      250    252    +2     
=====================================
+ Hits         1798   1812   +14
Impacted Files Coverage Δ
src/modules/builder/Builder.ts 100% <100%> (ø) ⬆️
src/database/Database.ts 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a48dea1...1c2eaa9. Read the comment docs.

const database = new Database()

database.register(User)
database.register(Hobby) // TODO custom module?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiaking
What do you think about testing this functionality with adding a custom module?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 😃

@kiaking

kiaking commented Dec 23, 2019

Copy link
Copy Markdown
Member

@SzNagyMisu Hi sorry for my late response! Do you think you can resolve the conflict...!?

@SzNagyMisu

Copy link
Copy Markdown
Author

Wow... Things have changed since... I'll give it a try

SzNagyMisu pushed a commit to SzNagyMisu/vuex-orm that referenced this pull request Jan 2, 2020
@SzNagyMisu

Copy link
Copy Markdown
Author

I've decided it will be cleaner if I start the whole PR from scratch - so many things have changed since.

@SzNagyMisu

Copy link
Copy Markdown
Author

Reopened PR at #535 - closing this one.

@SzNagyMisu SzNagyMisu closed this Jan 2, 2020
@SzNagyMisu SzNagyMisu deleted the 187-register-model-at-runtime branch February 3, 2020 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants