-
Notifications
You must be signed in to change notification settings - Fork 95
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
FindChildBlock throws an Error if Block given as string #1469
Conversation
@skad0 should also throw on |
common.blocks/i-bem-dom/i-bem-dom.js
Outdated
@@ -442,7 +442,10 @@ var BemDomEntity = inherit(/** @lends BemDomEntity.prototype */{ | |||
* @returns {Block} | |||
*/ | |||
findChildBlock : function(Block) { | |||
// TODO: throw if Block passed as a string | |||
if(typeof Block === 'string') { | |||
throw new Error('Block can\'t be a String'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message which describes what type Block
is allowed to be, might be more useful in case of error. Consider "Block must be a class or an instance", as an example.
🆙 |
cc @dfilatov |
|
8df32d2
to
bf77793
Compare
bf77793
to
38f10e4
Compare
38f10e4
to
57f78c0
Compare
🆙 |
lgtm |
typeof Block === 'object' && typeof Block.block === 'string' | ||
) { | ||
throw new Error('Block must be a class or description (block, modName, modVal) of the block to find'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- i still can pass primitives numbers, boolean, undefined
- any function
error message of this validation and validation description don't fit with code.
@@ -442,7 +456,8 @@ var BemDomEntity = inherit(/** @lends BemDomEntity.prototype */{ | |||
* @returns {Block} | |||
*/ | |||
findChildBlock : function(Block) { | |||
// TODO: throw if Block passed as a string | |||
validateBlockParam(Block); | |||
|
|||
return this._findEntities('find', Block, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we don't do this check at _findEntities
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'cos _findEntities
is also used for elements passed as strings
Referred to this
@tadatuta