3.0 beta 2

AX.Object

AX.Object class is a root of ActiveWidgets class hierarchy. Allows to define object properties, trigger and listen to events and perform data binding operations.

// create and initialize new object instance
var obj = new AX.Object({
    text: 'abc',
    value: 123
});

// attach an event handler
obj.on('text', function(){
    alert(this.text());
});

// modify property value
obj.value(345);

Provides support for simple inheritance and mixins.

// generate new class constructor
var MyClass = AX.Object.extend(function(){

    // initialize the prototype
    this.set({
        color: 'red',
        size: 1
    });

    this.on('size', function(){
        // do something
    });
});

Methods

bind( [propertyName], expression )

Creates binding rule, linking property propertyName to the expression. Most often the expression is just a reference to the individual data field. See Data Binding.

obj.bind('text', '$userName');

When propertyName is omitted, the binding is applied to the default property.

obj.bind('$userName');

The expressions allow simple in-place calculations or combining separate data fields into a single value.

obj.bind('total', '$price * $amount');

Parameters

  • propertyName - String (optional). The name of the bound property.
  • expression - String. Simple expression.

Returns

  • this (chainable)

bind( config )

Calls bind(name, value) for each name/value pair.

obj.bind({
    icon: '$productType',
    text: '$productDescription'
});

Parameters

  • config - Object. The configuration object (name/value pairs).

Returns

  • this (chainable)

data()

Returns bound data, if any. See Data Binding.

obj.data();

Returns

  • Any. The data value/object.

data( value )

Binds the component to the data value/object. Propagates to the child components according to the binding rules.

obj.data({
    firstName: 'John',
    lastName: 'Smith'
});

Parameters

  • value - Any|Promise. The new data value/object. Accepts promises.

Returns

  • this (chainable)

fireEvent( name, [event] )

Triggers an event. See Events.

obj.fireEvent('click');

Parameters

  • name - String. The name of the event.
  • event - Object (optional). The event object. Will be passed to the event handlers as the first argument.

Returns

  • this (chainable)

get( name )

Finds property name by going up the component tree and returns its value. See Properties.

obj.get('text');

Parameters

  • name - String. The name of the property/method to look for.

Returns

  • Any. The value of the property.

off( eventName, handler )

Removes an event handler. See Events.

obj.off('click', fn);

Parameters

  • eventName - String. The name of the event.
  • handler - Function. The event handler function.

Returns

  • this (chainable)

on( eventName, handler )

Adds an event handler. See Events.

obj.on('click', function(){
    alert('Hello');
});

Parameters

  • eventName - String. The name of the event.
  • handler - Function. The event handler function.

Returns

  • this (chainable)

parent()

Returns parent object.

obj.child().parent(); // returns obj

Returns

  • Object

set( name, value, [converter] )

Assigns the value to the property name. If the property accessor method does not exist yet, it will be created automatically. See Properties.

obj.set('color', 'red');

If called with converter, always re-creates the accessor method.

function px(value){

    if (typeof value == 'number'){
        return value + 'px';
    }

    return value;
}

obj.set('size', 0, px);

Parameters

  • name - String. The name of the property.
  • value - Any|Promise. The new property value. Accepts promises.
  • converter - Function (optional). The converter function.

Returns

  • this (chainable)

set( config )

Calls set(name, value) for each name/value pair.

obj.set({
    color: 'red',
    size: 123
});

Parameters

  • config - Object. The configuration object (name/value pairs).

Returns

  • this (chainable)

use( alias )

Adds the properties, methods and events of the alias class to the current object. See muliple inheritance/mixins.

obj.use('toolbar');

Parameters

  • alias - String|Array. The alias of the applied class (mixin) or array of aliases.

Returns

  • this (chainable)