Skip to content

Commit

Permalink
Migrate reflect and register to EventTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
snuggs committed Dec 21, 2018
1 parent a7040e7 commit 295d2cb
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions event-target/index.es
Expand Up @@ -77,5 +77,39 @@ const EventTarget = HTMLElement => // why buble
// // https://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget-dispatchEvent

// { }


// Reflection - https://en.wikipedia.org/wiki/Reflection_(computer_programming)
// Type Introspection - https://en.wikipedia.org/wiki/Type_introspection
//
// In computing, type introspection is the ability of a program
// to examine the type or properties of an object at runtime.
// Some programming languages possess this capability.
//
// Introspection should not be confused with reflection,
// which goes a step further and is the ability for a program to manipulate the values,
// meta-data, properties and/or functions of an object at runtime.


reflect (handler) {

/^on/.test (handler) // is a W3C `on`event
&& handler in HTMLElement.prototype // `on*`

&& // automagically delegate event
this.on ( handler.substr (2), this [handler] )
}


register (node, handler, event) {
for (let attribute of
[].slice.call (node.attributes))
/^on/.test (event = attribute.name)
// https://www.quirksmode.org/js/events_tradmod.html
// because under traditional registration the handler value is wrapped in scope `{ onfoo }`
&& ( handler = (/{\s*(\w+)/.exec (node [event]) || []) [1])
&& ( node [event] = this.renderable (this [handler]) )
}

})

0 comments on commit 295d2cb

Please sign in to comment.