-
-
Notifications
You must be signed in to change notification settings - Fork 46
Let DOM macros fail silently as a config option #290
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
Comments
While I don't disagree with having a configuration setting that the Author can use to disable the DOM macro's default behaviour, I do think it's important to point out one major difference between the macro's and the jQuery element search functions. And that is that the functions return an Array of elements that met the criteria. whose length can be checked to determine if the search failed. Where as the macros themselves don't allow the Author the same type of check, thus the need for an error message. |
Yes, I agree that there is a strong argument for the warning error being the default, just that a "don't warn me" mode would greatly expand the macros usefulness. I remember using this back in the day: <<if $(selector).length>>
<<addclass 'selector' 'class'>>
<</if>> Which fetches the selected items twice and offers no benefit over the simple Separate but related issue: I assume most
|
First. The issue with conflating the errors in question with the ones enabled by Anyway. jQuery users are, generally, more knowledgable than Twine/SugarCube users. When jQuery fails on a query, its users are more likely to know what's going on—in general, anyway. Twine/SugarCube users… not so much. The issue I have with this is that you're just moving where the problem shows up, not getting rid of it. Going from the macro returning an error informing users that no elements matched to silently swallowing the error is bound to cause all sorts of confusion. Thus, in general, I am not in favor of adding a setting that discards the errors.
Unfortunately, you cannot reliably use a navigation event here. While changes to state are available by this time, changes to the DOM likely are not. This is the main reason why The primary issue with simply doing this all the time is that it introduces timing issues that can really screw with user's brains—it's not always an issue, but when it is…. This is the entire reason that the
I do not wish to change the error to duplicate the documentation. It's both verbose and, should be, unnecessary. Of course, no one reads the damn documentation—🤬—so, I don't know. |
Uh oh!
There was an error while loading. Please reload this page.
Currently, DOM macros that do not find any matching element return a
no elements matched the selector...
.This means they cannot be used to target elements that may not be present, unlike their equivalent jQuery functions. Sure, the user can test whether the element is present before calling the macro, but if they know how to do it they might as well just call the function directly.
I agree with the idea that the user should know if the macro isn't doing anything but this behaviour also limits the applicable uses. That's why I feel it should be offered as a config option,
true
by default, similar toifAssignmentError
.A few name suggestions:
Config.macros.notInDomError
Config.macros.elementNotFoundError
Config.macros.noMatchedElementError
I can submit it as a pull request on
develop
if it is more convenient to do so, much love, Mali.The text was updated successfully, but these errors were encountered: