Skip to content
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

add Store#hasModule(path) API #834

Merged
merged 6 commits into from
Mar 25, 2020
Merged

add Store#hasModule(path) API #834

merged 6 commits into from
Mar 25, 2020

Conversation

FranckFreiburger
Copy link
Contributor

No description provided.

Copy link
Member

@ktsn ktsn left a comment

Choose a reason for hiding this comment

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

Can we add a unit test for this?

src/store.js Outdated
assert(Array.isArray(path), `module path must be a string or an Array.`)
}

this._modules.isRegistered(path)
Copy link
Member

Choose a reason for hiding this comment

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

We must return the result of this expression.

@@ -53,6 +53,14 @@ export default class ModuleCollection {

parent.removeChild(key)
}

isRegistered (path) {
const parent = this.get(path.slice(0, -1))
Copy link
Member

Choose a reason for hiding this comment

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

I realized this line can throw an error if the parent module does not exist.
To handle this, we also need to add existance check in get method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes,

store.registerModule('hi' ...
expect(store.hasModule('hi')).toBe(true)
expect(store.hasModule(['hi','big'])).toBe(false)
expect(store.hasModule(['hi','big', 'world'])).toBe(false) // THROW
expect(store.hasModule(['bonjour'])).toBe(false)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

store.registerModule(['aze', 'rty'], ... // THROW

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe this behavior is expected, maybe it's a documentation issue ?

Copy link
Member

Choose a reason for hiding this comment

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

But the purpose of this feature is to check existance of module, isn't it? I think the hasModule should return false in that case.

Copy link
Contributor Author

@FranckFreiburger FranckFreiburger Jun 15, 2017

Choose a reason for hiding this comment

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

yes, this feature is to check existence of module, but maybe not the existence of sub-module.
It's quite like mkdir and mkdirp
But I understand your point of view

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why this method is semantically related with mkdir. They are used on different platform (Web/CLI) and also are different kind of task (hasModule checks a module while mkdir creates a directory).

If the parent module does not exist, it's clear that its child module also does not exist. So why hasModule need to throw in that case? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trust me, I am not trying to create modules with mkdir 😃
I just wanted to say that the responsibility lies with the caller to ensure the correctness of the arguments.

@ktsn
Copy link
Member

ktsn commented Jul 5, 2017

  • Can we add a new test case for hasModule? Adding a test code to non-relevant test case would problematic since it would make harder to detect a real problem when the test cases fail.
  • Looks like CI is failed due to linting issue. Please check/fix it by running npm test on your terminal.

@FranckFreiburger
Copy link
Contributor Author

FranckFreiburger commented Jul 10, 2017

At this point, hasModule() behaves like registerModule() and unregisterModule() in term of error management, it throws if parent module does not exist.
I will propose a new PR for existence check in get method and update these 3 methods.

@anteriovieira
Copy link

What prevents it from being merged?

# Conflicts:
#	test/unit/modules.spec.js
@ktsn ktsn added the proposal label Jan 11, 2018
@trainiac
Copy link

trainiac commented Jun 8, 2018

@ktsn Can this be merged? Or does this PR need more work?

@mlanin
Copy link

mlanin commented Jul 26, 2018

@ktsn a year has passed. Can we merge this already? Please :)

@wa3l
Copy link
Contributor

wa3l commented Mar 20, 2019

@yyx990803 any timeline on merging this?

@mlavina
Copy link

mlavina commented May 24, 2019

@ktsn @yyx990803 This would also be really helpful to my team can we get this merged in and released?

@JasonLandbridge
Copy link

2020 now, this is such a small pull request. Just merge it already!

@ktsn ktsn merged commit d65d142 into vuejs:dev Mar 25, 2020
vaga pushed a commit to vaga/vuex that referenced this pull request Apr 20, 2020
* add Store#hasModule(path) API

* fix Store::hasModule(path) return value

* add unit test for Store#hasModule(path)

* Revert "add unit test for Store#hasModule(path)" (reverts commit 09f3197.)
Add a new test for Store#hasModule()

* fix linting issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants