Skip to content

Commit

Permalink
moar feature parity
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Feb 12, 2020
1 parent 729440f commit a138f50
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ export function bind(classObject: any) {
if (oldConnectedCallback) oldConnectedCallback.call(this)
for(const el of this.querySelectorAll('[data-action]')) {
for (const [eventName, ref, method] of bindings(el.getAttribute('data-action')||'', classObject.name)) {
this.addEventListener(eventName, (event: Event) => {
if (event.target === el) this[method](event)
let receiver = this
let delegate = el
if (ref === 'window') {
receiver = delegate = window
} else if (ref === 'document') {
receiver = delegate = document
}
receiver.addEventListener(eventName, (event: Event) => {
if (event.target === delegate) this[method](event)
})
}
}
Expand All @@ -32,7 +39,7 @@ export function target(proto: any, propertyKey: string) {
configurable: true,
get: function() {
const target = this.querySelector(
`[data-target="${this.constructor.name + "." + propertyKey}"]`
`[data-target=*"${this.constructor.name + "." + propertyKey}"]`
);
Object.defineProperty(this, propertyKey, {
value: target,
Expand Down

0 comments on commit a138f50

Please sign in to comment.