Documentation Should Include x-bind caveat for x-spread #1395
Replies: 7 comments
-
This is a JavaScript issue mostly, if you don't return anything, then there's no output We might want to handle the failure more gracefully + like you said docs, what would you have expected in the docs? |
Beta Was this translation helpful? Give feedback.
-
I think maybe some kind of caveat that makes it clear that returning something is sometimes necessary, and a warning in the console that notifies a function that expected to return something, returned nothing would be really helpful. |
Beta Was this translation helpful? Give feedback.
-
Yeah, I think the fact you're calling it a caveat is part of the issue. In the majority of cases (exception being event handlers) you're expected to return something. Any idea how we would make that clear?
the problem with this is that |
Beta Was this translation helpful? Give feedback.
-
The latest version shouldn't throw the error. However, this is just going to hide the real problem which is the fact that your code doesn't return anything so it translates to Generally speaking, you are always suppose to return something when using spread, the same value you would write in the directive using plain HTML. If you don't return anything, you'll probably see empty tags where you are expecting a value. |
Beta Was this translation helpful? Give feedback.
-
For me the confusion stemmed from the example in the documentation does not show a return statement, where in most cases a return statement would be necessary. I understand that a return statement isn't necessary in the example, and get why, but it still tripped me up. Maybe the update is as simple as providing a different, or additional example that uses a return statement? There's plenty of scenarios in Alpine where you don't explicitly use the So yeah, I get that it's not a "caveat", but I do think, at least in the context of Alpine, it does muddle expectations and would benefit from being a bit more explicit in the docs. |
Beta Was this translation helpful? Give feedback.
-
In the same example, a few lines below, it uses return for x-show. |
Beta Was this translation helpful? Give feedback.
-
Yeah, actually that's how I was able to figure it out. I noticed that used a return statement, but the wording makes the behavior sound specific to |
Beta Was this translation helpful? Give feedback.
-
Thanks so much for your work on Alpine. I've really enjoyed using it so-far!
In the docs, this is mentioned for
x-for
:However it appears that this also applies to
x-bind:
, as well.I'm unsure if this is an error on my part, a part of a bigger problem, or if it's simply something that should be specified in the docs. Either way, I only figured it out by sheer luck.
Here's the error that crops up when
return
is not included in the callback:It appears to happen in
handleAttributeBindingDirective
on this line:Beta Was this translation helpful? Give feedback.
All reactions