Skip to content

Internal references for event binding docs #468

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions current/en-us/4. binding/1. basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ The cancel button uses the `trigger` command to attach an event listener to the

Aurelia will automatically call [`preventDefault()`](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault) on events handled with `delegate` or `trigger` binding. Most of the time this is the behavior you want. To turn this off, return `true` from your event handler function.

### Related documentation
- [Delegate vs Trigger](/docs/binding/delegate-vs-trigger)
- [`self` binding behavior](/docs/binding/binding-behaviors#self)

## Function References

While developing custom elements or custom attributes you may encounter a situation where you have a `@bindable` property that expects a reference to a function. Use the `call` binding command to declare and pass a function to the bindable property. The `call` command is superior to the `bind` command for this use-case because it will execute the function in the correct context, ensuring `this` is what you expect it to be.
Expand Down
2 changes: 2 additions & 0 deletions current/en-us/4. binding/6. delegate-vs-trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ To find out if [event delegation](https://davidwalsh.name/event-delegate) can be

Here's the [MDN page for blur](https://developer.mozilla.org/en-US/docs/Web/Events/blur). It has further info on event delegation techniques for the blur and focus events.

When using `delegate` you might also want to use the [`self` binding behavior](/docs/binding/binding-behaviors#self).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may accidentally give wrong impression that either

  • delegate should be accompanied by self
  • only delegate can work with self

Maybe we can word it in a way that signals self is complementary to event, instead of enhancement. Something like this:

Aurelia provides a few binding behaviors to help define advance event handling behavior out of the box, please see
1...
2...
3...

@EisenbergEffect @fkleuver

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes of course, self can be used also for trigger! Sorry, I'm a little confused...

What other binding behaviors would be in that list?


### Exceptions to the general guidance above:

#### Use `trigger` on buttons when the following conditions are met:
Expand Down
4 changes: 4 additions & 0 deletions current/en-us/4. binding/9. binding-behaviors.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ onMouseDown(event) {
}
```

### Related documentation
- [The basics of binding DOM Events](/docs/binding/basics#dom-events)
- [Delegate vs Trigger](/docs/binding/delegate-vs-trigger)

## Custom binding behaviors

You can build custom binding behaviors just like you can build value converters. Instead of `toView` and `fromView` methods you'll create `bind(binding, scope, [...args])` and `unbind(binding, scope)` methods. In the bind method you'll add your behavior to the binding and in the unbind method you should cleanup whatever you did in the bind method to restore the binding instance to it's original state. The `binding` argument is the binding instance whose behavior you want to change. It's an implementation of the `Binding` interface. The `scope` argument is the binding's data-context. It provides access to the model the binding will be bound to via it's `bindingContext` and `overrideContext` properties.
Expand Down