Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
Fix for bug #546, added docs for event listeners on the host element.
Browse files Browse the repository at this point in the history
  • Loading branch information
marycampione committed Oct 21, 2014
1 parent fca5ffe commit 8931288
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/polymer/polymer.md
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,43 @@ Some things to notice:
* `inDetail`: A convenience form of `inEvent.detail`.
* `inSender`: A reference to the node that declared the handler. This is often different from `inEvent.target` (the lowest node that received the event) and `inEvent.currentTarget` (the component processing the event), so {{site.project_title}} provides it directly.

#### Imperative event mapping

Alternatively, you can add event handlers to a {{site.project_title}} element imperatively.

**Note:** In general, the declarative form is preferred.
{: .alert .alert-warning }

<polymer-element name="g-button">
<template>
<button>Click Me!</button>
</template>
<script>
Polymer({
eventDelegates: {
up: 'onTap',
down: 'onTap'
},
onTap: function(e, detail, sender) {
...
}
});
</script>
</polymer-element>

The example adds event listeners for `up` and `down` events
to the {{site.project_title}} element called `g-button`.
The listeners are added to the host element rather than to individual
elements within it.
These listeners handle events on the host element itself,
in addition to events that bubble up from within the host element.
You can still set event listeners on individual elements within the host.

The keys within the `eventDelegates` object are the event names to listen for.
The values are the callback function names, here `onTap`.
Event handler functions defined imperatively
receive the same arguments as those defined declaratively.

### Observing properties {#observeprops}

#### Changed watchers {#change-watchers}
Expand Down

0 comments on commit 8931288

Please sign in to comment.