Options
All
  • Public
  • Public/Protected
  • All
Menu

Module u-components

Component references in LibJS are always an instance of one of the component classes found in the u-components module. You can not create new instances of a component using these classes, but you can manipulate an existing component in your app using the properties and methods that each component class exposes.

This example shows a few different ways of getting a component, and interacting with them.

var uComps = require('u-components');
var uActions = require('u-actions');
var Action = uActions.Action;
var uPages = require('u-pages');

new Action('Fade Image', fadeImage).register();
function fadeImage() {
var logoImg = uPages.current.components.getImage('Big Logo');
logoImg.filename = 'umajin_logo.png';
logoImg.alpha = 30;
console.log(logoImg.height);

var homePage = uPages.get('Home Page');
// Better to use `getButton` here, but using `get` and passing in the type as an argument is always an option.
var myBtn = homePage.components.get('My Button', uComps.ComponentType.BUTTON);
myBtn.on(uComps.ComponentEvent.PRESS, function() {
console.log('Button has been pressed!');
});
}

If you need to find all the components within a page, you can use the innerComponents property as this example shows:

var uComps = require('u-components');
var uActions = require('u-actions');
var Action = uActions.Action;
var uPages = require('u-pages');

new Action('All Components Test', allComponents).register();
function allComponents() {
var allComponents = uPages.current.innerComponents;
for (var i = 0; i < allComponents.length; i++) {
var comp = allComponents[i];
var testComp = uComps.cast.to(comp)
console.log(testComp.name)
console.log(testComp.type)
}
}

Index

Variables