ycom
yo-yo
components with classes and events.
Usage
const Component =
The module exports Component
, a class that should be extended for use by consumers. Component
extends EventEmitter
, so passing events around is supported out of the box.
#constructor(opts)
- opts: Passed to
EventEmitter
. Optional.
#render(): HTMLElement
Should be overridden by consumers to return an instance of HTMLElement
.
Check out the npm packages bel, hyperx, and yo-yo for easy generation of HTMLElement
instances from Javascript.
#added() / Event: added
When the component node is added to the document, the added
prototype method will be called, and the added
event will be fired.
#removed() / Event: removed
When the component node is removed from the document, the removed
prototype method will be called, and the removed
event will be fired.
get #node
Returns the node currently assigned to the component, or generates one if it doesn't exist.
Example
const Component = const yo = { super // You can pass arguments to the EventEmitter constructor here (optional). thismessage = message } { console } { console } { return yo`<em></em>` // compose the component rendering function here } let component = message: "Hello Javascript!" componentcomponent documentbody
License
MIT