Skip to content
Armagan Amcalar edited this page Jan 9, 2015 · 3 revisions

Component Idea No:1

Controller:

/**
 * This is a sample controller.
 *
 * @contructor
 * @extends {tart.ui.View}
 *
 * @param {string} id Resource id.
 */
sk.Example = function(id) {
	var model = new sk.ExampleModel(id);
	goog.base(this, model);
};

sk.Example.prototype.foo = function() {
	return 'bar';
};

Model:

/**
 * This is a sample model.
 *
 * @contructor
 * @extends {tart.ui.ViewModel}
 *
 * @param {string} id Resource id.
 */
sk.ExampleModel = function(id) {
	goog.base(this);
    
    this.id = id;
    
    this.fetch();
};

sk.ExampleMode.prototype.fetch = function() {
	xhr('/test/' + id, function(err, data) {
    	this.data = data;
    	this.dispatchEvent(tart.ui.View.MODEL_CHANGED);
    }, this);
};

Template:

function render()  {
    return h('div', {
        style: {
            textAlign: 'center',
            width: (data.length > 40 ? 100 + 80) + 'px',
        }
    }, [String(data)]);
}
Clone this wiki locally