convert to APF style mixins

This commit is contained in:
Fabian Jakobs 2010-04-22 13:41:32 +02:00
commit 1b37c1c6f2
7 changed files with 46 additions and 45 deletions

View file

@ -44,7 +44,7 @@ ace.BackgroundTokenizer = function(tokenizer) {
(function(){ (function(){
ace.mixin(this, ace.MEventEmitter); ace.implement(this, ace.MEventEmitter);
this.setTokenizer = function(tokenizer) { this.setTokenizer = function(tokenizer) {
this.tokenizer = tokenizer; this.tokenizer = tokenizer;

View file

@ -15,7 +15,7 @@ ace.Document = function(text, mode) {
(function() { (function() {
ace.mixin(ace.Document.prototype, ace.MEventEmitter); ace.implement(this, ace.MEventEmitter);
this._split = function(text) { this._split = function(text) {
return text.split(/\r\n|\r|\n/); return text.split(/\r\n|\r|\n/);

View file

@ -1,10 +1,12 @@
ace.provide("ace.MEventEmitter"); ace.provide("ace.MEventEmitter");
ace.MEventEmitter.$initEvents = function() { ace.MEventEmitter = function() {
this._eventRegistry = {};
};
ace.MEventEmitter.$dispatchEvent = function(eventName, e) { this.$initEvents = function() {
this._eventRegistry = {};
};
this.$dispatchEvent = function(eventName, e) {
var listeners = this._eventRegistry[eventName]; var listeners = this._eventRegistry[eventName];
if (!listeners || !listeners.length) return; if (!listeners || !listeners.length) return;
@ -14,9 +16,9 @@ ace.MEventEmitter.$dispatchEvent = function(eventName, e) {
for (var i=0; i<listeners.length; i++) { for (var i=0; i<listeners.length; i++) {
listeners[i](e); listeners[i](e);
} }
}; };
ace.MEventEmitter.addEventListener = function(eventName, callback) { this.addEventListener = function(eventName, callback) {
var listeners = this._eventRegistry[eventName]; var listeners = this._eventRegistry[eventName];
if (!listeners) { if (!listeners) {
var listeners = this._eventRegistry[eventName] = []; var listeners = this._eventRegistry[eventName] = [];
@ -24,9 +26,9 @@ ace.MEventEmitter.addEventListener = function(eventName, callback) {
if (ace.arrayIndexOf(listeners, callback) == -1) { if (ace.arrayIndexOf(listeners, callback) == -1) {
listeners.push(callback); listeners.push(callback);
} }
}; };
ace.MEventEmitter.removeEventListener = function(eventName, callback) { this.removeEventListener = function(eventName, callback) {
var listeners = this._eventRegistry[eventName]; var listeners = this._eventRegistry[eventName];
if (!listeners) { if (!listeners) {
return; return;
@ -35,4 +37,5 @@ ace.MEventEmitter.removeEventListener = function(eventName, callback) {
if (index !== -1) { if (index !== -1) {
listeners.splice(index, 1); listeners.splice(index, 1);
} }
};
}; };

View file

@ -19,7 +19,7 @@ ace.ScrollBar = function(parent) {
(function() { (function() {
ace.mixin(ace.ScrollBar.prototype, ace.MEventEmitter); ace.implement(this, ace.MEventEmitter);
this.onScroll = function() { this.onScroll = function() {
this.$dispatchEvent("scroll", {data: this.element.scrollTop}); this.$dispatchEvent("scroll", {data: this.element.scrollTop});

View file

@ -14,7 +14,7 @@ ace.Selection = function(doc) {
(function() { (function() {
ace.mixin(ace.Selection.prototype, ace.MEventEmitter); ace.implement(this, ace.MEventEmitter);
this.updateCursor = function() { this.updateCursor = function() {
this.$dispatchEvent("changeCursor", { data: this.getCursor() }); this.$dispatchEvent("changeCursor", { data: this.getCursor() });

View file

@ -21,10 +21,8 @@ ace.inherits = function(ctor, superCtor) {
ctor.prototype.constructor = ctor; ctor.prototype.constructor = ctor;
}; };
ace.mixin = function(obj, mixin) { ace.implement = function(proto, mixin) {
for (var key in mixin) { mixin.call(proto);
obj[key] = mixin[key];
}
}; };
ace.addListener = function(elem, type, callback) { ace.addListener = function(elem, type, callback) {

View file

@ -1,7 +1,7 @@
var EventEmitter = function() { var EventEmitter = function() {
this.$initEvents(); this.$initEvents();
}; };
ace.mixin(EventEmitter.prototype, ace.MEventEmitter); ace.implement(EventEmitter.prototype, ace.MEventEmitter);
var EventEmitterTest = new TestCase("EventEmitterTest", { var EventEmitterTest = new TestCase("EventEmitterTest", {
"test: dispatch event with no data" : function() { "test: dispatch event with no data" : function() {