Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upHandle view.query() being invoked when view.el is undefined #91
Comments
bear
added
the
bug
label
Dec 27, 2014
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wraithgar
Jan 5, 2015
Member
In cases like this we've tended towards a more helpful exception. If you query against a nonexistent el it should still probably throw, but it should throw a specific error like 'this.el not defined'
ETA: This is just my opinion, adding discussion label.
|
In cases like this we've tended towards a more helpful exception. If you query against a nonexistent el it should still probably throw, but it should throw a specific error like 'this.el not defined' ETA: This is just my opinion, adding discussion label. |
wraithgar
added
the
discussion
label
Jan 5, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
kamilogorek
Jan 6, 2015
Member
Agree with @wraithgar Querying is only possible on rendered elements or something similar.
|
Agree with @wraithgar |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wraithgar
Jan 6, 2015
Member
Just to be clear, the current options are: add the guard to query that already exists in queryAll, or make both throw a descriptive exception if this.el is not defined
|
Just to be clear, the current options are: add the guard to query that already exists in queryAll, or make both throw a descriptive exception if this.el is not defined |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nirrek
Jan 6, 2015
I think having a useful exception thrown is preferable to simply returning an empty array or undefined.
Empty array / undefined should mean that DOM traversal was correctly performed, but there were no matches found.
When el is undefined, you never actually perform a search at all. This will never be the intention of the user, so they should be notified that they are doing something incorrectly.
Possible exception message:
Query cannot be performed as this.el is not defined. Ensure that the view has been rendered.
nirrek
commented
Jan 6, 2015
|
I think having a useful exception thrown is preferable to simply returning an empty array or undefined. Empty array / undefined should mean that DOM traversal was correctly performed, but there were no matches found. When el is undefined, you never actually perform a search at all. This will never be the intention of the user, so they should be notified that they are doing something incorrectly. Possible exception message: |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wraithgar
Jan 6, 2015
Member
I like that. This would still be a breaking change as anyone currently relying on the guard statement would now be getting an exception thrown.
|
I like that. This would still be a breaking change as anyone currently relying on the guard statement would now be getting an exception thrown. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
pgilad
Jun 5, 2015
Member
^ Added a PR for this. I agree error should be thrown as to be verbose.
Notice:
- Change queryAll to first throw if this.el doesn't exist, then possibly return [this.el] if !selector.
- Breaking change for
queryAll - Test?
|
^ Added a PR for this. I agree error should be thrown as to be verbose.
|
nirrek commentedDec 26, 2014
Currently, if
view.elis undefined, a call toview.query()will fail with aUncaught TypeError: Illegal invocationinside thematches-selectorpackage. It would be nicer to have a check in the query method that handles this condition.You have a guard for this condition in the
queryAllmethod, just not in thequerymethod.