Comments (10)
@jdanyow Can you investigate what it would take to do something like this? I think we might have another issue related to that, so search for that and see if their scenarios align.
See if we can come up with a way to enable this.
from binding.
possibly related to #50
from binding.
@stoffeastrom Here's an idea I have. Let me know if this would work.
What if we allow you to pass anything you want to your own method via call. But, similar to .delegate and .trigger, we set up the special $event value. The creator of the custom attribute could then call your function, passing it an event args that would become the $event in the consumer's method. Does that make sense?
So, the consumer would write this:
<div oribella-tap="end.call: onTap($event,data,contact);"></div>
And the attribute would do this:
export class OribellaTap {
doSomething(){
var eventArgs = {}; //something interesting here
this.end(eventArgs);
}
}
The "eventArgs" object becomes the $event parameter in the method. Would that work?
from binding.
It sounds like it in theory :).
So I guess that I could add whatever property on the eventArgs
property I want to expose. So actually it would be
<div oribella-tap="end.call: onTap($event ,contact);"></div>
and I add
var eventArgs = {
event: event,
data: data
}
That should work. So we have a common way of exposing behavior scoped things in the eventArgs object :)
from binding.
Yes, that's my idea. Then this would also model the way DOM events works as well.
from binding.
I believe this is a breaking change...
My custom element's .call
bindables all stopped being able to pass parameters when updating and I think it is because of this.
Is there somewhere I can go to see how to fix them? In particular, what do I need to do to make them work now?
Previously I did this:
app.html
<custom-element callback.call="myFunction()"></custom-element>
app.js
export class App {
myFunction(param) {
console.log(param);
}
}
custom-element.js
export class CustomElement {
@bindable callback;
someMethod() {
callback("foo");
}
}
Previously, the above code would log "foo". Now it logs "undefined".
from binding.
It appears (correct me if I am wrong) that app.js from above needs to change to:
export class App {
myFunction() {
console.log(this.$event);
}
}
If this is correct, then I would like to express my concern with this change. The first problem I see with this change is that the custom-element is modifying my view-model directly, not just through the bound properties. In particular, it is setting $event
on my view-model. This is even more problematic if you want to use something like TypeScript for static typing because you are now stuck working with $event
as any
since you may have multiple callbacks in place, which would prevent you from statically typing $event
on your view-model.
Secondly is discoverability. Previously, I could define my custom-element like so:
export class CustomElement {
@bindable callback: (param: string) => void;
someMethod() {
callback("foo");
}
}
This would allow the reader to easily find out that the callback they provide must be a function that takes a string. Also, if I were using TypeScript, I would be forced to match that signature while authoring CustomElement. This is particularly important if I am firing the callback from multiple locations in my source code.
In the new system, if I am understanding it correctly, we have lost not only discoverability of what exactly will be provided in the callback but we are also munging other people's objects which, IMO, is a bad practice.
from binding.
Your binding expression should pass $event rather than use this. Also, the modification of the view model is a temporary hack until after we make some more fundamental changes to the binding system, which will correct this and other issues.
If you want discoverability, you should define the shape of the event object that the custom element will pass.
from binding.
@EisenbergEffect Can you provide some clarity on what you mean by
Your binding expression should pass $event rather than use this.
I don't know what that statement translates to in code. It seems that everyone else "gets it" so I am guessing my misunderstanding is due to my newbieness in JavaScript.
from binding.
callback.call="myFunction($event)"
(Im on mobile- unable to format the code properly)
from binding.
Related Issues (20)
- path expressions containing 'in' no longer working, 'in' treated as keyword HOT 3
- Issue with aurelia/binding typings HOT 12
- Issue with interpolation binding inside HTML `<option>` element HOT 2
- Checkbox event arguments in repeaters not binding correctly HOT 5
- @behel33 Thanks for creating the issue, I couldn't recreate the behavior you described, can you help fix this codesandbox https://codesandbox.io/s/x761qq5p3q HOT 1
- Infinite loop with 100+ observers HOT 17
- click.delegate bindings stop working HOT 14
- click.delegate firing for all clicks on firefox rather than just left click HOT 5
- Binding on role attribute not working in Firefox HOT 4
- Delegate event bubbling does not match native behavior in shadow dom
- Infinite loop in aurelia-bindingd.ts OverrideContext HOT 13
- parsing of template issue: ${moment().toISOString()} does not work HOT 1
- Parser Error: Invalid start of expression at column 0 in expression []
- Optimizing getter access HOT 1
- Matcher ignored within repeater HOT 7
- Delegate does not support shadow dom for Firefox
- getContextFor() doesn't handle a non-object bindingContext HOT 3
- Can we use/make attached/detached method inside aurelia custom element? HOT 3
- Binding checkboxes: custom matcher does not work when using repeat.for HOT 3
- SetterObserver keeps old value retained HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from binding.