Sha256: 04e357b2d6fb572068a4f7d7076474d5621a8e46e3b9aad0586af6614a6ae8b5

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

include('data.js');
/**
 * Легковесная поддержка событий без баблинга
 */
uki.data.Observable = {
    bind: function(name, callback) {
        var _this = this;
        callback.huid = callback.huid || uki.guid++;
        uki.each(name.split(' '), function(i, name) {
            _this._observersFor(name).push(callback);
        });
    },
    
    unbind: function(name, callback) {
        var _this = this;
        uki.each(name.split(' '), function(i, name) {
            _this._observers[name] = !callback ? [] : uki.grep(_this._observersFor(name), function(c) {
                return c != callback && c.huid != callback.huid;
            });
            if (_this._observers[name]) delete _this._observers[name];
        });
    },
    
    trigger: function(name/*, data1, data2*/) {
        var attrs = Array.prototype.slice.call(arguments, 1);
        uki.each(this._observersFor(name, true), function(i, callback) {
            callback.apply(this, attrs);
        }, this);
    },
    
    _observersFor: function(name, skipCreate) {
        if (skipCreate && (!this._observers || !this._observers[name])) return [];
        if (!this._observers) this._observers = {};
        if (!this._observers[name]) this._observers[name] = [];
        return this._observers[name];
    }
};

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
uki-1.1.4 frameworks/uki/src/uki-data/observable.js
uki-1.1.3 frameworks/uki/src/uki-data/observable.js
uki-1.1.2 frameworks/uki/src/uki-data/observable.js
uki-1.1.1 frameworks/uki/src/uki-data/observable.js
uki-1.1.0 frameworks/uki/src/uki-data/observable.js
uki-1.0.2 frameworks/uki/src/uki-data/observable.js