HTML要素の様にイベントを伝播するオブザーバーを実現するライブラリ。
var composite = new Composite;
composite.on('event-name', function(e, arg) {
// write code.
});
var eventaction = function(e, arg) {
// write code.
};
composite.one('event-name', eventaction);
composite.off('event-name', eventaction);
composite.off('event-name');
composite.emit('event-name', arg, function() {
// callback.
});
var composite_parent = new Composite,
composite_child = new Composite;
composite_parent.addChild(composite_child);
composite_parent.removeChild(composite_child);
composite_parent.removeChild();
// composite.emit === composite.bubble
composite_child.on('event-bubble', function() {
// call 1.
});
composite_parent.on('event-bubble', function() {
// call 2.
});
composite_child.bubble('event-bubble');
composite_child.on('event-capture', function() {
// call 2.
});
composite_parent.on('event-capture', function() {
// call 1.
});
composite_parent.capture('event-capture');
composite_child.on('event-propagation', function(e) {
e.stopPropagation();
});
composite_parent.on('event-propagation', function(e) {
// don't execute.
});
composite_child.emit('event-propagation');
composite.on('event-default', function(e) {
// don't execute.
});
composite.on('event-default', function(e) {
e.preventDefault();
});
composite.emit('event-default');
composite_child.only('event-only');
composite.dispose();
var ExtendComposite = Composite.extend({
init: function(config) {
// write init code.
},
method1: function() {
// write method.
},
on: function() {
// override method.
// call super method.
this._super.apply(this, arguments);
},
});