llama
v2.2.0
Published
Wooley, sure-footed. A very small kit of reusable UI utilities.
Readme
Llama toolkit
Wooly, sure-footed, a thin layer above vanilla JS for SPA dev (no dependencies).
Provides:
- a Component API
- an event-bus
- a router
API Doc
Table of Contents
llama
Set all the Llama goodness together
Parameters
optionsObject the configuration optionsoptions.boxstring? the id of the div we load components inoptions.eventBusEventBus? an event-bus to pass to the different Componentsoptions.contextObject? a shared context object for all the routesoptions.routesObject<string, (Class<Component> | RouteTarget)> the description of routesoptions.loggerConsole? define a logger, can be {logger: console} to send on the javascript console
RouteTarget
Type: Object
Properties
typeClass<Component>?namestring? name of the component to serve as source for event listenersboxstring? the id of an HTML element the component is rendered intosub_boxstring? the id of an HTML element the embedded sub-component are rendered intocssstring? a string of CSS to be injectedloggerConsole? define a logger, can be {logger: console} to send on the javascript consoleembedObject<string, RouteTarget> embedded route
Component
Common ground for vanilla Widget Component
Parameters
optionsObject a set of option aloptions.namestring? name of the component to serve as source for event listenersoptions.boxstring? the id of the HTMLElement to which we want to plug the componentoptions.eventBusEventBus? to receive and send eventsoptions.contextObject<string, any>?options.loggerConsole? define a logger, can be {logger: console} to send on the javascript consoleoptions.cssstring?
listen
Listen events
call
Call for loading of the component
Parameters
load
Load component inside the box
Parameters
unload
Unload component
prepareBox
Returns (ShadowRoot | HTMLElement)
populate
Parameters
addChildren
Parameters
removeChildren
Parameters
children...Component
init
init the component after appending to DOM
Parameters
postLoad
activate after load
Parameters
clean
clean the component after removing from DOM
on
Attach an event listener for this source component
Parameters
emit
Emit an event for a given key that are sent to every attached events listeners
Parameters
kstring the event keyp...any the optional args
gId
Parameters
idstring
Returns HTMLElement
addEvtById
Parameters
idstringevtanycbany
hasHTML
Returns boolean
empty
Clear the box contents
Parameters
boxNode (optional, defaultthis.prepareBox())
fragmentFromHtml
Generate DOM Element from source HTML
Parameters
htmlstring some HTML code
Returns DocumentFragment the generated DOM Element
injectCSS
Inject component defined CSS into the box (if it exists)
Parameters
boxNode (optional, defaultthis.prepareBox())
injectHTML
Inject component defined HTML into the box (if it exists)
Parameters
HostComponent
A component that host embedded Component
setSubRoute
Parameters
SimpleEventBus
A simple event bus to enable event-driven architecture
Parameters
optionsObject optional parameters
on
Attach an event listener for a source
Parameters
sstring name of the source of the listenere(string | Array<string>) the event(s) key(s) to attach the listenerf
emit
Emit an event for a given key that are sent to every attached events listeners
Parameters
kstring the event keyp...any the optional args
clear
Clear event listeners for a source
Parameters
sstring the name of the source to clear events forfilter(optional, default()=>true)
SequenceEventBus
A Complex event bus to enable event-driven architecture with a before and after event hook
Parameters
optionsObject optional parametersoptions.loggerConsole? define a logger, can be {logger: console} to send on the javascript console
on
Attach an event listener for a source
Parameters
sstring name of the source of the listenere(string | Array<string>) the event(s) key(s) to attach the listenerf
emit
Emit an event for a given key that are sent to every attached events listeners
Parameters
kstring the event keyp...any the optional args
clear
Clear event listeners for a source
Parameters
sstring the name of the source to clear events forfilter(optional, default()=>true)
Router
A simple router for Llama Component
Parameters
eventBusEventBusoptionsobject?options.loggerConsole? define a logger, can be {logger: console} to send on the javascript console
routes
Properties
routesArray<Path>
before
Parameters
actionfunction
on
Parameters
run
Run the router
stop
Stop the router
go
Go to a route matching the given path
Parameters
pathstring
route
Route the browser
