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
Event expressions - RFC #2386
Event expressions - RFC #2386
Conversation
I'm in favor of this one. But I'd suggest
Method calls all the way! Burn the old event syntax! 🎆 🔥 🚒
I method calls, possibly just args I guess? <div transition="transitionName({ in: { duration: 5 }, out: { duration: 10 }})></div> ...or maybe multiple setup calls <div transition="transitionName('in', 5); transitionName('out', 10);"></div> Not sure how transitions are written, just throwing in ideas.
Partial support in 0.8 with warning log, remove from code by 0.9. Isn't that the usual mo?
Explicit is always better than implicit. 😄 |
What @fskreuz said. |
@guilhermeaiolfi |
I really |
I originally went with At any rate, if that is to be changed it needs to be soon, because |
For me I understand the need to align events to resolve similar to references, so I think this is a good change overall. Once folk gets used to calling @ractive.foo() maybe we can revisit shortening it to just @foo(). I appreciate the arguments against adding symbols to the template, but once @ractive.xxx is entrenched, maybe we would appreciate a shortcut more ;-) |
actually, I kind of like @sabob 's idea that all EDIT: just to be clear, I am using edge and I do have EDIT2: another idea is |
@evs-chris I'm convinced 😄 Noted down in the docs repo to document the different @sabob @heavyk The use of |
yeah I agree with
|
|
@martypdx hmmm, I actually never cognitively connected that inconsistency with the data and instance methods (and I've written a lot of ractive now!!). I wonder how I missed that. so what you're proposing then is for it to instead be TBH, I could dig that... I do like that syntax introduced in #2345, a lot 👍 |
@martypdx regarding 2, after the deprecation, yes, I would have the parser rewrite the argument of |
@guilhermeaiolfi I'm starting to like to the idea of |
let's just alias |
I've got to third the |
Although, If we do go with call data methods: It kinda works, and avoids the |
Mixing mustaches inside an expressions has been a PITA, both from an implementation perspective and IMO as a developer because you end up in "mixed-mode" javascript and html template land. The goal is to use mustaches for html and text interpolation, allow javascript expressions inside mustaches and inside plugin attribute directive values. The other benefit to use a marker instead of assuming the first token of an event handler applies a method name is that the expression itself can more more dynamic as multiple actions can be invoked: on-click="@this.set( 'x', foo ), @this.set( 'y', bar )"
on-click="@this.push( 'items', newItem ).then( _ => @this.set( 'newItem' ) )" [note: AFAIK, neither of those examples is currently supported even with this PR, @evs-chris?] While arguably there is an initial learning in having both {{#each items}}
<li on-click="@this.select( this )">{{this.name}}</li>
{{/each}} I was going for succinctness in shortening that to |
@martypdx no, but |
That's what I thought, but that's a bit of a hack and feels error prone when people use them with functions that have a falsey return. Maybe allow the comma operator so this expression can be properly, um, expressed:
yep. and future drum of worms for sure. |
It's not exactly the comma operator per se, but I added support for a list of expressions. The last value in the list is the one used for cancelling. |
Coming back to it after a bit of time has elapsed, I've also updated the intro comment with the result of the other bits of discussion here. The general consensus seemed to be that this is a good way forward, so any thoughts on getting this in for 0.8 or 0.9 (or not at all)? |
So much goodness to wait until 0.9. Since it's ready, ship it. 0.8 from me. |
0.8, ho! |
0.8 is good from this end 👍 |
I've been coming back to something @guilhermeaiolfi said: If we put aside the BREAKING CHANGE aspect, I prefer an API where You could still use Thoughts? @evs-chris sorry about being 11th hour :) |
@martypdx No complaints about that. I concede to whatever Chris and you like there. If you follow that train of thought, shouldn't all data/context refs start with So...
To remain consistent |
@martypdx well I'm not really for it, but I'm not really against it either. I like that All that said, I think it would be pretty easy change to make. Anyone else (especially @Rich-Harris)? |
@evs-chris, @JonDum for the record, I'm not actually advocating |
btw -
Only first item would be breaking change as others have not been introduced. |
good point (especially the service workers), I think that mapping to is quite reasonable. is there some way that could be combined in some way with your state idea in #2345 too? maybe we can define our own |
Thread becoming long, adding just one more to hopefully seal the deal. Let's all agree to this proposal:
It becomes clear when you put it like this:
That should be enough of a guideline to avoid confusion. We should steer away from keyword-specific to a broader view (had to re-read the thread and my silly comments to realize). A doc page for Really looking forward to 0.8 (as if I weren't using edge all this time). |
@evs-chris @fskreuz I think we should merge this now, because it changes or supports a number of other features that are already in edge (like |
Is the '@this' prefix required from now on? |
@kouts yes, it works without |
@kouts, @guilhermeaiolfi Though it is deprecated if you check the console:
whereas default firing by name w/o args is still supported:
|
Yeah, I think I said that somewhere. Not just for events, for properties in general it would be nice to avoid using '@this'. I would like to avoid those features that differ ractive from pure javascript. The exception being when there is analog way of doing that in javascript. |
I've been going through all my components preparing them for this change. Now having used it extensively... I'm really not a fan of all the clutter. 90% of the time I'm just doing a
+1 to that. If you did want to call a method on your data, can't you use (except for the |
I'm personally opposed to anything that makes the same reference resolve to different things in different contexts. My designer buddies have a hard enough time with one set of rules 😆 I think we should land something like #2345 that, among other things, makes |
I've already switched to @this, but an alternative is always nice to have. |
well, I'm not fan of Now you can do this:
If I'd be a noob, I'd just be confused 😲 ...especially since there are already My 2 cents. |
I'm a huge fan of the #2345 PR (but more for the state part about it). the that being said, I believe @JonDum brings up a good point. in my code, I almost never use |
This is my attempt to resolve #1172, #1396, #2311, and partially #2176. It is also somewhat tied to #2369.
What this does
This takes event handling and unifies it as an expression instead of having special parsing for handling method events. This opens event handling up to everything possible with an expression in Ractive. Here're a few examples:
on-click=".loadStuff()"
on-click="@this.reset.partial('foo')"
oron-click=".foo().and.bar(., 'yep')"
on-click="@this.parent.doAThing(.)"
on-click="@this.toggle('foo') && @this.fire('fooed')"
or since these are parsed as a liston-click="@this.toggle('foo'), @this.fire('fooed')"
I have also taken the spread args and made it available anywhere, which is what ES2015 allows e.g.
on-foo="fn('hi', ...arguments, 42)"
is perfectly legal. It is also extended to any other call expression with any reference e.g.{{ doThing(foo, ...bars, baz, ...bats) }}
. I implemented this by half-shimming with an IIFE based on Babel's output. There may be a better way, but this didn't require an extensive refactor.Additionally, dollar args (
$1
) andarguments
refs are now allowed to have children as per #2311. These are handled in the same way asevent
refs with children.Comments specifically requested
Updated
Method events are handled in their current state my detecting basicallyConsensus is that non-specific calls should be removed, so they are deprecated here and would be removed later.^someName(.*)\s*$
, prepending@this.
, and handling as an expression. This seems to work pretty well in practice, but is it confusing thattoggle('foo')
,.toggle('foo')
, and~/toggle('foo')
mean potentially very different things? With the confusion surrounding where method events actually call, should they just be deprecated and eventually removed in favor of@this.method(args)
? Deprecating and removing plain method call events would eliminate the remaining inconsistency in template reference resolution.I haven't addressed proxy events in this PR yet, because I'd like some feedback first. I would prefer to support only no-args events (option 3) for auto-proxying, which would be super simple to support here. Is that what most people would like to do? The only other thing I consider tenable from a parsing (code and mental) viewpoint is to supportArgumented proxy events are deprecated here and would be removed later.on-click="nameExpression:argsList"
. That would makeon-click="{{ foo ? 'bar' : 'baz'}}: {{bop}},bip,{{ { oh: 'my' } }}"
becomeon-click="( foo ? 'bar' : 'baz' ): bop, 'bip', { oh: 'my' }"
.I also haven't addressed decorator and transition args yet, because I'd like some feedback first. I would prefer to drop mustaches in the directives entirely and just move to comma separated expression lists for decorators and transitions. That combined withThis is addressed in Second swing at conditional directives: Revenge of the Fragment - RFC #2369.as-decoratorName
andtransitionName-in
/transitionName-out
/transitionName-in-out
(or something similar) and the changes in Second swing at conditional directives: Revenge of the Fragment - RFC #2369 would allow that. This would be more consistent with event directives. Another proposal has been to treat them as method calls instead e.g.decorator="decoratorName(arg1, arg2)"
which seems reasonable, but I think it's less consistent and could get weird with transitions with their in/out/in-out facets.How should deprecation be handled?I'd kinda like for this to land for 0.8 now, since it's still compatible with 0.7 and would let the big cleanup start immediately after 0.8.Status
arguments
, and dollar args in expressionsarguments
, tests, and more tests- the deprecation path leaves the old proxy handling code in place, so only expression-related stuff is tested beyond the existing event testsClean up codemostly deferred until after deprecation cycle - there's lots of code that can go away and/or be nicely refactored