Skip to content
Browse files

There were changes in Evento: evento.addEventListener, evento.removeE…

…ventListener, and evento.purgeEventListener to evento.on, evento.off, and evento.purge respectively. Update Maria to reflect these changes.
  • Loading branch information...
1 parent 0b52233 commit 36c0d18eeab65b295a52de22a984ea8805384685 @petermichaux committed
View
12 doc/quick-start-tutorial-for-the-impatient.html
@@ -162,7 +162,7 @@
<pre><code>> var view = {update: function(evt) {console.log('The model changed!');}};
undefined
-> maria.addEventListener(todoModel, 'change', view, 'update');
+> maria.on(todoModel, 'change', view, 'update');
undefined</code></pre>
<p>Now a change to the model object&rsquo;s done value will cause the model to call the view&rsquo;s <code>update</code> method.<p>
@@ -173,7 +173,7 @@
<p>If we remove the observer from the model and change the done value again, we see the view is no longer notified.</p>
-<pre><code>> maria.removeEventListener(todoModel, 'change', view, 'update');
+<pre><code>> maria.off(todoModel, 'change', view, 'update');
undefined
todoModel.setDone(false);
undefined
@@ -438,7 +438,7 @@
undefined
> var view = {update: function(evt) {console.log(evt.addedTargets.map(function(todo) {return todo.getContent();}));}};
undefined
-> maria.addEventListener(todosModel, 'change', view, 'update');
+> maria.on(todosModel, 'change', view, 'update');
undefined</code></pre>
<p>Now add a to-do to the set.</p>
@@ -524,7 +524,7 @@
<p>To see a list in the browser, let&rsquo;s update the <code>checkit/src/js/bootstrap.js</code> file to create a set model containing a few to-do items and add a view to the page.</p>
<pre><code>
-maria.addEventListener(window, 'load', function() {
+maria.on(window, 'load', function() {
var todosModel = new checkit.TodosModel();
@@ -663,7 +663,7 @@
<p>Update the <code>checkit/src/js/bootstrap.js</code> so that the to-do set starts empty and the input form is added.</p>
-<pre><code>maria.addEventListener(window, 'load', function() {
+<pre><code>maria.on(window, 'load', function() {
var model = new checkit.TodosModel();
@@ -796,7 +796,7 @@
<p>Create a new toolbar view during bootstrapping in <code>checkit/src/js/bootstrap.js</code>.</p>
-<pre><code>maria.addEventListener(window, 'load', function() {
+<pre><code>maria.on(window, 'load', function() {
var model = new checkit.TodosModel();
View
4 eg/checkit/src/js/bootstrap.js
@@ -1,4 +1,4 @@
-maria.addEventListener(window, 'load', function() {
+maria.on(window, 'load', function() {
var loading = document.getElementById('loading');
loading.parentNode.removeChild(loading);
@@ -7,7 +7,7 @@ maria.addEventListener(window, 'load', function() {
var store = localStorage.getItem('todos-maria');
model = store ? checkit.TodosModel.fromJSON(JSON.parse(store)) :
new checkit.TodosModel();
- evento.addEventListener(model, 'change', function() {
+ maria.on(model, 'change', function() {
localStorage.setItem('todos-maria', JSON.stringify(model.toJSON()));
});
}
View
2 eg/timeit/src/js/bootstrap.js
@@ -1,4 +1,4 @@
-maria.addEventListener(window, 'load', function() {
+maria.on(window, 'load', function() {
var loading = document.getElementById('loading');
loading.parentNode.removeChild(loading);
View
10 lib/evento/evento-min.js
@@ -21,13 +21,13 @@ return bundle;}
function bundlesAreEqual(a,b){return(a.element===b.element)&&(a.type===b.type)&&(a.listener===b.listener)&&((!a.hasOwnProperty('auxArg')&&!b.hasOwnProperty('auxArg'))||(a.hasOwnProperty('auxArg')&&b.hasOwnProperty('auxArg')&&(a.auxArg===b.auxArg)));}
function indexOfBundle(bundles,bundle){for(var i=0,ilen=bundles.length;i<ilen;i++){if(bundlesAreEqual(bundles[i],bundle)){return i;}}
return-1;}
-evento.addEventListener=function(element,type,listener,auxArg){var bundle=createBundle.apply(null,arguments);if(listener._evento_bundles){if(indexOfBundle(listener._evento_bundles,bundle)>=0){return;}}
+evento.on=function(element,type,listener,auxArg){var bundle=createBundle.apply(null,arguments);if(listener._evento_bundles){if(indexOfBundle(listener._evento_bundles,bundle)>=0){return;}}
else{listener._evento_bundles=[];}
if(typeof bundle.element.addEventListener==='function'){bundle.element.addEventListener(bundle.type,bundle.wrappedHandler,false);}
else if((typeof bundle.element.attachEvent==='object')&&(bundle.element.attachEvent!==null)){bundle.element.attachEvent('on'+bundle.type,bundle.wrappedHandler);}
-else{throw new Error('evento.addEventListener: Supported EventTarget interface not found.');}
-listener._evento_bundles.push(bundle);};var remove=evento.removeEventListener=function(element,type,listener,auxArg){if(listener._evento_bundles){var i=indexOfBundle(listener._evento_bundles,createBundle.apply(null,arguments));if(i>=0){var bundle=listener._evento_bundles[i];if(typeof bundle.element.removeEventListener==='function'){bundle.element.removeEventListener(bundle.type,bundle.wrappedHandler,false);}
+else{throw new Error('evento.on: Supported EventTarget interface not found.');}
+listener._evento_bundles.push(bundle);};var remove=evento.off=function(element,type,listener,auxArg){if(listener._evento_bundles){var i=indexOfBundle(listener._evento_bundles,createBundle.apply(null,arguments));if(i>=0){var bundle=listener._evento_bundles[i];if(typeof bundle.element.removeEventListener==='function'){bundle.element.removeEventListener(bundle.type,bundle.wrappedHandler,false);}
else if((typeof bundle.element.detachEvent==='object')&&(bundle.element.detachEvent!==null)){bundle.element.detachEvent('on'+bundle.type,bundle.wrappedHandler);}
-else{throw new Error('evento.removeEventListener: Supported EventTarget interface not found.');}
-listener._evento_bundles.splice(i,1);}}};evento.purgeEventListener=function(listener){if(listener._evento_bundles){var bundles=listener._evento_bundles.slice(0);for(var i=0,ilen=bundles.length;i<ilen;i++){var bundle=bundles[i];if(bundle.hasOwnProperty('auxArg')){remove(bundle.element,bundle.type,bundle.listener,bundle.auxArg);}
+else{throw new Error('evento.off: Supported EventTarget interface not found.');}
+listener._evento_bundles.splice(i,1);}}};evento.purge=function(listener){if(listener._evento_bundles){var bundles=listener._evento_bundles.slice(0);for(var i=0,ilen=bundles.length;i<ilen;i++){var bundle=bundles[i];if(bundle.hasOwnProperty('auxArg')){remove(bundle.element,bundle.type,bundle.listener,bundle.auxArg);}
else{remove(bundle.element,bundle.type,bundle.listener);}}}};}());
View
48 lib/evento/evento.js
@@ -292,7 +292,7 @@ o.dispatchEvent({type:'change'});
}());
/**
-@property evento.addEventListener
+@property evento.on
@parameter element {EventTarget} The object you'd like to observe.
@@ -324,27 +324,27 @@ var o = {
};
// late binding. handleEvent is found when each event is dispatched
-evento.addEventListener(document.body, 'click', o);
+evento.on(document.body, 'click', o);
// late binding. handleClick is found when each event is dispatched
-evento.addEventListener(document.body, 'click', o, 'handleClick');
+evento.on(document.body, 'click', o, 'handleClick');
// early binding. The supplied function is bound now
-evento.addEventListener(document.body, 'click', o, o.handleClick);
-evento.addEventListener(document.body, 'click', o, function(){});
+evento.on(document.body, 'click', o, o.handleClick);
+evento.on(document.body, 'click', o, function(){});
// supplied function will be called with document.body as this object
-evento.addEventListener(document.body, 'click', function(){});
+evento.on(document.body, 'click', function(){});
// The following form is supported but is not neccessary given the options
// above and it is recommended you avoid it.
-evento.addEventListener(document.body, 'click', this.handleClick, this);
+evento.on(document.body, 'click', this.handleClick, this);
*/
/**
-@property evento.removeEventListener
+@property evento.off
@parameter element {EventTarget} The object you'd like to stop observing.
@@ -360,25 +360,25 @@ Removes added listener matching the element/type/listener/auxArg combination exa
If this combination is not found there are no errors.
var o = {handleEvent:function(){}, handleClick:function(){}};
-evento.removeEventListener(document.body, 'click', o);
-evento.removeEventListener(document.body, 'click', o, 'handleClick');
-evento.removeEventListener(document.body, 'click', o, fn);
-evento.removeEventListener(document.body, 'click', fn);
-evento.removeEventListener(document.body, 'click', this.handleClick, this);
+evento.off(document.body, 'click', o);
+evento.off(document.body, 'click', o, 'handleClick');
+evento.off(document.body, 'click', o, fn);
+evento.off(document.body, 'click', fn);
+evento.off(document.body, 'click', this.handleClick, this);
*/
/**
-@property evento.purgeEventListener
+@property evento.purge
@parameter listener {EventListener} The listener object that should stop listening.
@description
-Removes all registrations of the listener added through evento.addEventListener.
+Removes all registrations of the listener added through evento.on.
This purging should be done before your application code looses its last reference
-to listener. (This can also be done with more work using evento.removeEventListener for
+to listener. (This can also be done with more work using evento.off for
each registeration.) If the listeners are not removed or purged, the listener
will continue to observe the EventTarget and cannot be garbage collected. In an
MVC application this can lead to "zombie views" if the model data cannot be
@@ -397,8 +397,8 @@ var APP_BoxView = function(model, controller) {
// implementing the EventTarget interface using listener objects
// and specifying method name using the same subscription interface.
//
- evento.addEventListener(this.rootEl, 'click', this, 'handleClick');
- evento.addEventListener(this.model, 'change', this, 'handleModelChange');
+ evento.on(this.rootEl, 'click', this, 'handleClick');
+ evento.on(this.model, 'change', this, 'handleModelChange');
};
APP_BoxView.prototype.handleClick = function() {
@@ -415,7 +415,7 @@ APP_BoxView.prototype.destroy = function() {
// to DOM nodes, model objects, or anything else implementing
// the EventTarget interface in one fell swoop.
//
- evento.purgeEventListener(this);
+ evento.purge(this);
};
*/
@@ -471,7 +471,7 @@ APP_BoxView.prototype.destroy = function() {
return -1;
}
- evento.addEventListener = function(element, type, listener, /*optional*/ auxArg) {
+ evento.on = function(element, type, listener, /*optional*/ auxArg) {
// Want to call createBundle with the same number of arguments
// that were passed to this function. Using apply preserves
// the number of arguments.
@@ -493,12 +493,12 @@ APP_BoxView.prototype.destroy = function() {
bundle.element.attachEvent('on'+bundle.type, bundle.wrappedHandler);
}
else {
- throw new Error('evento.addEventListener: Supported EventTarget interface not found.');
+ throw new Error('evento.on: Supported EventTarget interface not found.');
}
listener._evento_bundles.push(bundle);
};
- var remove = evento.removeEventListener = function(element, type, listener, /*optional*/ auxArg) {
+ var remove = evento.off = function(element, type, listener, /*optional*/ auxArg) {
if (listener._evento_bundles) {
var i = indexOfBundle(listener._evento_bundles, createBundle.apply(null, arguments));
if (i >= 0) {
@@ -511,14 +511,14 @@ APP_BoxView.prototype.destroy = function() {
bundle.element.detachEvent('on'+bundle.type, bundle.wrappedHandler);
}
else {
- throw new Error('evento.removeEventListener: Supported EventTarget interface not found.');
+ throw new Error('evento.off: Supported EventTarget interface not found.');
}
listener._evento_bundles.splice(i, 1);
}
}
};
- evento.purgeEventListener = function(listener) {
+ evento.purge = function(listener) {
if (listener._evento_bundles) {
var bundles = listener._evento_bundles.slice(0);
for (var i = 0, ilen = bundles.length; i < ilen; i++) {
View
2 src/ElementView.js
@@ -226,7 +226,7 @@ maria.ElementView.prototype.buildTemplate = function() {
methodName = uiActions[key],
elements = this.findAll(selector, this._rootEl);
for (var i = 0, ilen = elements.length; i < ilen; i++) {
- maria.addEventListener(elements[i], eventType, this, methodName);
+ maria.on(elements[i], eventType, this, methodName);
}
}
}
View
4 src/Model.js
@@ -21,7 +21,7 @@ when a "change" event is dispatched on the model objects.
alert('The model changed!');
}
};
- maria.addEventListener(model, 'change', view, 'update');
+ maria.on(model, 'change', view, 'update');
The model can dispatch a "change" event on itself when the model
changes.
@@ -46,7 +46,7 @@ including that data on the event object.
An event listener can be removed from a model object.
- maria.removeEventListener(model, 'change', view, 'update');
+ maria.off(model, 'change', view, 'update');
A particularly useful pattern is using maria.Model as the "superclass"
of your application's model. The following example shows how this
View
2 src/SetModel.js
@@ -31,7 +31,7 @@ events when elements are added or deleted from the the set.
alert(setModel.length + ' element(s) in the set.');
}
};
- maria.addEventListener(setModel, 'change', view, 'update');
+ maria.on(setModel, 'change', view, 'update');
You can add elements to the set. Adding an element
that is already in the set has no effect. The add method returns
View
6 src/View.js
@@ -133,7 +133,7 @@ maria.View.prototype = maria.create(hijos.Node.prototype);
maria.View.prototype.constructor = maria.View;
maria.View.prototype.destroy = function() {
- maria.purgeEventListener(this);
+ maria.purge(this);
this._model = null;
if (this._controller) {
this._controller.destroy();
@@ -185,7 +185,7 @@ maria.View.prototype._setModelAndController = function(model, controller) {
eventMap = this._lastModelActions;
for (type in eventMap) {
if (Object.prototype.hasOwnProperty.call(eventMap, type)) {
- maria.removeEventListener(this._model, type, this, eventMap[type]);
+ maria.off(this._model, type, this, eventMap[type]);
}
}
delete this._lastModelActions;
@@ -194,7 +194,7 @@ maria.View.prototype._setModelAndController = function(model, controller) {
eventMap = this._lastModelActions = this.getModelActions() || {};
for (type in eventMap) {
if (Object.prototype.hasOwnProperty.call(eventMap, type)) {
- maria.addEventListener(model, type, this, eventMap[type]);
+ maria.on(model, type, this, eventMap[type]);
}
}
}
View
12 src/borrowEvento.js
@@ -1,11 +1,11 @@
-maria.addEventListener = function() {
- evento.addEventListener.apply(this, arguments);
+maria.on = function() {
+ evento.on.apply(this, arguments);
};
-maria.removeEventListener = function() {
- evento.removeEventListener.apply(this, arguments);
+maria.off = function() {
+ evento.off.apply(this, arguments);
};
-maria.purgeEventListener = function() {
- evento.purgeEventListener.apply(this, arguments);
+maria.purge = function() {
+ evento.purge.apply(this, arguments);
};
View
8 tst/ElementView-suite.js
@@ -68,8 +68,8 @@
var args = [];
- var originalAddEventListener = maria.addEventListener;
- maria.addEventListener = function(node, eventType, listener, methodName) {
+ var originalOn = maria.on;
+ maria.on = function(node, eventType, listener, methodName) {
args.push({
node: node,
eventType: eventType,
@@ -81,7 +81,7 @@
// next line will trigger creation of DOM node and addition of listeners.
elementView.build();
- assert.same(4, args.length, 'maria.addEventListener should have been called four times');
+ assert.same(4, args.length, 'maria.on should have been called four times');
// need a predictable order to test
args.sort(function(a, b) {
@@ -115,7 +115,7 @@
assert.same(elementView, args[3].listener);
assert.same('onMouseoverDiv', args[3].methodName);
- maria.addEventListener = originalAddEventListener;
+ maria.on = originalOn;
},
"test build returns a DOM node": function() {
View
14 tst/View-suite.js
@@ -49,8 +49,8 @@
var args = [];
- var originalAddEventListener = maria.addEventListener;
- maria.addEventListener = function(node, eventType, listener, methodName) {
+ var originalOn = maria.on;
+ maria.on = function(node, eventType, listener, methodName) {
args.push({
node: node,
eventType: eventType,
@@ -63,7 +63,7 @@
var model = new maria.Model();
view.setModel(model);
- assert.same(2, args.length, 'evento.addEventListener should have been called twice');
+ assert.same(2, args.length, 'maria.on should have been called twice');
// need a predictable order to test
args.sort(function(a, b) {
@@ -84,7 +84,7 @@
assert.same(view, args[1].listener);
assert.same('onSquished', args[1].methodName);
- maria.addEventListener = originalAddEventListener;
+ maria.on = originalOn;
},
"test when model changed unsubscribe from previous model": function() {
@@ -99,8 +99,8 @@
var args = [];
- var originalRemoveEventListener = maria.removeEventListener;
- maria.removeEventListener = function(node, eventType, listener, methodName) {
+ var originalRemoveEventListener = maria.off;
+ maria.off = function(node, eventType, listener, methodName) {
args.push({
node: node,
eventType: eventType,
@@ -139,7 +139,7 @@
assert.same(view, args[1].listener);
assert.same('onSquished', args[1].methodName);
- maria.removeEventListener = originalRemoveEventListener;
+ maria.off = originalRemoveEventListener;
},
"test after destroy the model has no listeners": function() {

0 comments on commit 36c0d18

Please sign in to comment.
Something went wrong with that request. Please try again.