to get web components working include the component library
warning : 95% stable
the component.js library exposes a mod object, which holds as its keys the component modules, the key is either the element nodename, or its id, the id can be used when the page contains multiple of the same component
var editor = mod['web-editor'];
var editor2 = mod.myEditor;
any elements with a [ component ] attribute will be treated as a web component module
this example demonstrates the web-editor ext-code.com
Many of the official components, at this time, require some boiler plate code, mainly small dependencies.
http://libs.ext-code.com/js/dom/component/v3.0/component.js?hdr
adding the
?hdr
search parameter automatically sets up the default boilerplate, which for most of the official
components is all that is required.
When the ?hdr parameter is used, after component initialisation is complete, a user function is called. This function can can be named any of these names :
Here is a simple example that includes the web-console ext-code.com
The code for a component, note :
(function({mod,host}){
})
var obj = {
version : 'v2.0'
};
return obj;
obj.initmod = function(){}
obj.init = function(){}
obj.initdom = function(){}
Skeletal function definition :
A typical component / module lifecycle might have :
Components are also effectively namespaced so they are free to load any other components that they may need without having to worry that there will ever be a clash of variables or tag names.
View the full list of components
html component list
View the
component.js
library documentation and api
component library
Here is a very simple component
and the code to include it
It is entirely possible to have components that do not adhere to the above standard lifecycle :
and the code to include it
Here we have to give the component.js library a chance to load and build the component,
mod.stack[]
is an array of functions that get run when the component.js library has finished initialising. Also an init function will
automatically be called.
The trouble with this approach is that as web pages and components get more complex, they start relyng on co-depencies, or they require the same resources that can potentially be loaded multiple times. The standard lifecycle is a way out of that. Often the component itself needs to load resources to be able to run, the component.js library provides a mechanism to ensure that all components on the page are loaded and available.
Note also that the only way here to access properties and methods of the component is to add them to the host element itself ( this is the way custom web-elements behave ), this is a problematic approach.
The component library just needs to be included as a script tag, it exposes a global property mod, it runs on window.onload, it has a loading stack that allows initialisation to be delayed until the asynchronous loading is complete.
Here is a simple setup that loads the log-mod element. Its function is to log toaster style messages in a webpage.
var registry = new ComponentRegistry();