picocomponent
Teeny tiny component system 🔍
Usage
var PicoComponent = { PicoComponent thisel = document} Buttonprototype = Object Buttonprototype { thiselinnerText = text return thisel} var button = documentbody
API
PicoComponent.prototype
PicoComponent
aims to provide a Class like interface for constructing components.
As a consumer you'll always want to extend the PicoComponent.prototype
either via ES6 classes:
// ...
or by extending the base prototype
:
{ PicoComponent} Buttonprototype = Object
Instances of PicoComponent
have the following internal properties:
this.el
: Used to manage the DOM node a component is responsible for. Defaults tonull
. See How do I manage DOM nodes for more info.
PicoComponent.prototype.render(...args)
You'll always want to implement a render function. This forms the public interface for your
component, and will generally leverage some templating library to manage rendering and updating
your component. Your render
method should always return DOM nodes.
PicoComponent.prototype.connect()
When assigned, the connect
handler will be called once your component has been inserted into the DOM.
PicoComponent.prototype.disconnect()
When assigned, the disconnect
handler will be called once your component has been removed
from the DOM.
FAQ
Is this a joke?
It may seem that way, but seriously this exists as a result of other component systems eg.
nanocomponent
being focused on producing components targeted at DOM morphing
libraries such as nanomorph
and morphdom
.
For this reason picocomponent
aims to be more general purpose, leaving DOM diffing strategies up to the consumer,
while still providing useful features such as connect
/disconnect
event listeners by integrating on-load
.
How do I manage DOM nodes
As a matter of convention PicoComponent
implements a custom getter/setter used for managing
the DOM node your component is responsible for.
When assigning a DOM node to your PicoComponent
instance eg:
{ super thisel = document }
PicoComponent
will ensure all appropriate lifecycle hooks are correctly assigned.
Have you gone too far?
Eh.
See also:
- joshgillies/hypercomponent
- yoshuawuyts/nanocomponent
- yoshuawuyts/microcomponent
- yoshuawuyts/cache-element
- hypermodules/cache-component
License
MIT