Commit 2b680e1f authored by Stephen Sawchuk's avatar Stephen Sawchuk

maria uses bower for all dependencies.

parent c18448ee
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"todomvc-common": "~0.1.4", "todomvc-common": "~0.1.4",
"director": "~1.2.0" "director": "~1.2.0",
"maria-bower": "~1.0.0",
"aristocrat-bower": "~1.0.1"
} }
} }
/* /*
Aristocrat version 2 Aristocrat version 1.0.1
Copyright (c) 2012, Peter Michaux Copyright (c) 2012, Peter Michaux
All rights reserved. All rights reserved.
Licensed under the Simplified BSD License. Licensed under the Simplified BSD License.
...@@ -78,7 +78,7 @@ aristocrat.removeClass(document.body, 'king'); ...@@ -78,7 +78,7 @@ aristocrat.removeClass(document.body, 'king');
var re = getRegExp(className); var re = getRegExp(className);
while (re.test(el.className)) { // in case multiple occurrences while (re.test(el.className)) { // in case multiple occurrences
el.className = el.className.replace(re, ' '); el.className = el.className.replace(re, ' ');
} }
}; };
/** /**
......
var maria = (function() { // IIFE
/* /*
Evento version 0 - JavaScript libraries for working with the observer pattern Evento version 1
Copyright (c) 2012, Peter Michaux Copyright (c) 2013, Peter Michaux
All rights reserved. All rights reserved.
Licensed under the Simplified BSD License. Licensed under the Simplified BSD License.
https://github.com/petermichaux/evento/blob/master/LICENSE https://github.com/petermichaux/evento/blob/master/LICENSE
...@@ -172,7 +173,7 @@ Call `evt.stopPropagation()` to stop bubbling to parents. ...@@ -172,7 +173,7 @@ Call `evt.stopPropagation()` to stop bubbling to parents.
*/ */
evento.EventTarget.prototype.dispatchEvent = function(evt) { evento.EventTarget.prototype.dispatchEvent = function(evt) {
// Want to ensure we don't alter the evt object passed in as it // Want to ensure we don't alter the evt object passed in as it
// may be a bubbling event. So clone it and then setting currentTarget // may be a bubbling event. So clone it and then setting currentTarget
// won't break some event that is already being dispatched. // won't break some event that is already being dispatched.
evt = create(evt); evt = create(evt);
...@@ -190,9 +191,9 @@ Call `evt.stopPropagation()` to stop bubbling to parents. ...@@ -190,9 +191,9 @@ Call `evt.stopPropagation()` to stop bubbling to parents.
// //
// Without making a copy, one listener removing // Without making a copy, one listener removing
// an already-called listener would result in skipping // an already-called listener would result in skipping
// a not-yet-called listener. One listener removing // a not-yet-called listener. One listener removing
// a not-yet-called listener would result in skipping that // a not-yet-called listener would result in skipping that
// not-yet-called listner. The worst case scenario // not-yet-called listner. The worst case scenario
// is a listener removing and adding itself again which would // is a listener removing and adding itself again which would
// create an infinite loop. // create an infinite loop.
// //
...@@ -267,7 +268,7 @@ Example 2 ...@@ -267,7 +268,7 @@ Example 2
(typeof pt[p] === 'function')) { (typeof pt[p] === 'function')) {
obj[p] = pt[p]; obj[p] = pt[p];
} }
} }
evento.EventTarget.call(obj); evento.EventTarget.call(obj);
}; };
...@@ -357,7 +358,7 @@ MVC application this can lead to "zombie views" if the model data cannot be ...@@ -357,7 +358,7 @@ MVC application this can lead to "zombie views" if the model data cannot be
garbage collected. Event listeners need to be removed from event targets in browsers garbage collected. Event listeners need to be removed from event targets in browsers
with circular reference memory leak problems (i.e. old versions of Internet Explorer.) with circular reference memory leak problems (i.e. old versions of Internet Explorer.)
The primary motivation for this `purge` function is to ease cleanup in MVC View destroy The primary motivation for this `purge` function is to ease cleanup in MVC View destroy
methods. For example, methods. For example,
var APP_BoxView = function(model, controller) { var APP_BoxView = function(model, controller) {
...@@ -456,13 +457,13 @@ methods. For example, ...@@ -456,13 +457,13 @@ methods. For example,
if (indexOfBundle(listener._evento_bundles, bundle) >= 0) { if (indexOfBundle(listener._evento_bundles, bundle) >= 0) {
// do not add the same listener twice // do not add the same listener twice
return; return;
} }
} }
else { else {
listener._evento_bundles = []; listener._evento_bundles = [];
} }
if (typeof bundle.element.addEventListener === 'function') { if (typeof bundle.element.addEventListener === 'function') {
bundle.element.addEventListener(bundle.type, bundle.wrappedHandler, false); bundle.element.addEventListener(bundle.type, bundle.wrappedHandler, false);
} }
else if ((typeof bundle.element.attachEvent === 'object') && else if ((typeof bundle.element.attachEvent === 'object') &&
(bundle.element.attachEvent !== null)) { (bundle.element.attachEvent !== null)) {
...@@ -481,14 +482,14 @@ methods. For example, ...@@ -481,14 +482,14 @@ methods. For example,
var bundle = listener._evento_bundles[i]; var bundle = listener._evento_bundles[i];
if (typeof bundle.element.removeEventListener === 'function') { if (typeof bundle.element.removeEventListener === 'function') {
bundle.element.removeEventListener(bundle.type, bundle.wrappedHandler, false); bundle.element.removeEventListener(bundle.type, bundle.wrappedHandler, false);
} }
else if ((typeof bundle.element.detachEvent === 'object') && else if ((typeof bundle.element.detachEvent === 'object') &&
(bundle.element.detachEvent !== null)) { (bundle.element.detachEvent !== null)) {
bundle.element.detachEvent('on'+bundle.type, bundle.wrappedHandler); bundle.element.detachEvent('on'+bundle.type, bundle.wrappedHandler);
} }
else { else {
throw new Error('evento.off: Supported EventTarget interface not found.'); throw new Error('evento.off: Supported EventTarget interface not found.');
} }
listener._evento_bundles.splice(i, 1); listener._evento_bundles.splice(i, 1);
} }
} }
...@@ -511,7 +512,7 @@ methods. For example, ...@@ -511,7 +512,7 @@ methods. For example,
}()); }());
/* /*
Hijos version 3 Hijos version 1.0.3
Copyright (c) 2013, Peter Michaux Copyright (c) 2013, Peter Michaux
All rights reserved. All rights reserved.
Licensed under the Simplified BSD License. Licensed under the Simplified BSD License.
...@@ -759,6 +760,11 @@ hijos.Node.prototype.insertBefore = function(newChild, oldChild) { ...@@ -759,6 +760,11 @@ hijos.Node.prototype.insertBefore = function(newChild, oldChild) {
} }
node = node.parentNode; node = node.parentNode;
} }
// remove from previous composite
var parent = newChild.parentNode;
if (parent) {
parent.removeChild(newChild);
}
// continue with insertion // continue with insertion
var children = this.childNodes; var children = this.childNodes;
// find index for newChild // find index for newChild
...@@ -778,11 +784,6 @@ hijos.Node.prototype.insertBefore = function(newChild, oldChild) { ...@@ -778,11 +784,6 @@ hijos.Node.prototype.insertBefore = function(newChild, oldChild) {
throw new Error('hijos.Node.prototype.insertBefore: Node was not found.'); throw new Error('hijos.Node.prototype.insertBefore: Node was not found.');
} }
} }
// remove from previous composite
var parent = newChild.parentNode;
if (parent) {
parent.removeChild(newChild);
}
// add to this composite // add to this composite
children.splice(indexForNewChild, 0, newChild); children.splice(indexForNewChild, 0, newChild);
this.firstChild = children[0]; this.firstChild = children[0];
...@@ -1018,7 +1019,7 @@ don't want to have a loop of thousands with calls to this function. ...@@ -1018,7 +1019,7 @@ don't want to have a loop of thousands with calls to this function.
// IE will trim when setting innerHTML so unify for all browsers // IE will trim when setting innerHTML so unify for all browsers
html = trim(html); html = trim(html);
var parser = defaultParser; var parser = defaultParser;
var matches = html.match(tagRegExp); var matches = html.match(tagRegExp);
if (matches) { if (matches) {
var name = matches[1].toLowerCase(); var name = matches[1].toLowerCase();
if (Object.prototype.hasOwnProperty.call(parsers, name)) { if (Object.prototype.hasOwnProperty.call(parsers, name)) {
...@@ -1219,8 +1220,8 @@ The rest of the details are the same as for grail.findAll. ...@@ -1219,8 +1220,8 @@ The rest of the details are the same as for grail.findAll.
}()); }());
/* /*
Hormigas version 4 Hormigas version 5
Copyright (c) 2012, Peter Michaux Copyright (c) 2013, Peter Michaux
All rights reserved. All rights reserved.
Licensed under the Simplified BSD License. Licensed under the Simplified BSD License.
https://github.com/petermichaux/hormigas/blob/master/LICENSE https://github.com/petermichaux/hormigas/blob/master/LICENSE
...@@ -1243,7 +1244,7 @@ var hormigas = {}; ...@@ -1243,7 +1244,7 @@ var hormigas = {};
function initSet(set) { function initSet(set) {
set._hormigas_ObjectSet_elements = {}; set._hormigas_ObjectSet_elements = {};
set.length = 0; set.size = 0;
} }
/** /**
...@@ -1259,17 +1260,17 @@ Do not attempt to add primitives or host objects in a `ObjectSet`. This ...@@ -1259,17 +1260,17 @@ Do not attempt to add primitives or host objects in a `ObjectSet`. This
is a compromise to make `ObjectSet` objects efficient for use in the model is a compromise to make `ObjectSet` objects efficient for use in the model
layer of your MVC-style application. layer of your MVC-style application.
When using the set iterators (e.g. `forEach`, `map`) do not depend When using the set iterators (e.g. `forEach`) do not depend
on the order of iteration of the set's elements. `ObjectSet` objects are unordered. on the order of iteration of the set's elements. `ObjectSet` objects are unordered.
var set = new hormigas.ObjectSet(); // an empty set var set = new hormigas.ObjectSet(); // an empty set
`ObjectSet` objects have a `length` property that is the number of elements in the set. `ObjectSet` objects have a `size` property that is the number of elements in the set.
var alpha = {}; var alpha = {};
var beta = {}; var beta = {};
var set = new hormigas.ObjectSet(alpha, beta, alpha); var set = new hormigas.ObjectSet(alpha, beta, alpha);
set.length; // 2 set.size; // 2
The methods of an `ObjectSet` object are inspired by the incomplete The methods of an `ObjectSet` object are inspired by the incomplete
Harmony Set proposal and the `Array.prototype` iterators. Harmony Set proposal and the `Array.prototype` iterators.
...@@ -1290,25 +1291,11 @@ Harmony Set proposal and the `Array.prototype` iterators. ...@@ -1290,25 +1291,11 @@ Harmony Set proposal and the `Array.prototype` iterators.
The number of elements in the set. The number of elements in the set.
*/ @member hormigas.ObjectSet.prototype.size
hormigas.ObjectSet.prototype.length = 0;
/**
Use to determine if the set has any elements or not.
var alpha = {};
var set = new hormigas.ObjectSet(alpha);
set.isEmpty(); // false
set['delete'](alpha);
set.isEmpty(); // true
@return {boolean} `true` if set is empty. Otherwise `false`. @readonly
*/ */
hormigas.ObjectSet.prototype.isEmpty = function() {
return this.length < 1;
};
/** /**
...@@ -1354,7 +1341,7 @@ If `element` is not already in the set then adds element to the set. ...@@ -1354,7 +1341,7 @@ If `element` is not already in the set then adds element to the set.
element._hormigas_ObjectSet_id = getId(); element._hormigas_ObjectSet_id = getId();
} }
this._hormigas_ObjectSet_elements[element._hormigas_ObjectSet_id] = element; this._hormigas_ObjectSet_elements[element._hormigas_ObjectSet_id] = element;
this.length++; this.size++;
return true; return true;
} }
}; };
...@@ -1380,7 +1367,7 @@ position so quote `delete`. ...@@ -1380,7 +1367,7 @@ position so quote `delete`.
hormigas.ObjectSet.prototype['delete'] = function(element) { hormigas.ObjectSet.prototype['delete'] = function(element) {
if (this.has(element)) { if (this.has(element)) {
delete this._hormigas_ObjectSet_elements[element._hormigas_ObjectSet_id]; delete this._hormigas_ObjectSet_elements[element._hormigas_ObjectSet_id];
this.length--; this.size--;
return true; return true;
} }
else { else {
...@@ -1394,14 +1381,14 @@ If the set has elements then removes all the elements. ...@@ -1394,14 +1381,14 @@ If the set has elements then removes all the elements.
var alpha = {}; var alpha = {};
var set = new hormigas.ObjectSet(alpha); var set = new hormigas.ObjectSet(alpha);
set.empty(); // true set.clear(); // true
set.empty(); // false set.clear(); // false
@return {boolean} `true` if elements were deleted from the set as the result of this call. Otherwise `false` because no elements were in the set. @return {boolean} `true` if elements were deleted from the set as the result of this call. Otherwise `false` because no elements were in the set.
*/ */
hormigas.ObjectSet.prototype.empty = function() { hormigas.ObjectSet.prototype.clear = function() {
if (this.length > 0) { if (this.size > 0) {
initSet(this); initSet(this);
return true; return true;
} }
...@@ -1435,7 +1422,7 @@ Calls `callbackfn` for each element of the set. ...@@ -1435,7 +1422,7 @@ Calls `callbackfn` for each element of the set.
var beta = {value: 1}; var beta = {value: 1};
var gamma = {value: 2}; var gamma = {value: 2};
var set = new hormigas.ObjectSet(alpha, beta, gamma); var set = new hormigas.ObjectSet(alpha, beta, gamma);
set.forEach(function(element, set) { set.forEach(function(element) {
console.log(element.value); console.log(element.value);
}); });
...@@ -1448,7 +1435,7 @@ Calls `callbackfn` for each element of the set. ...@@ -1448,7 +1435,7 @@ Calls `callbackfn` for each element of the set.
var thisArg = arguments[1]; var thisArg = arguments[1];
for (var p in this._hormigas_ObjectSet_elements) { for (var p in this._hormigas_ObjectSet_elements) {
if (Object.prototype.hasOwnProperty.call(this._hormigas_ObjectSet_elements, p)) { if (Object.prototype.hasOwnProperty.call(this._hormigas_ObjectSet_elements, p)) {
callbackfn.call(thisArg, this._hormigas_ObjectSet_elements[p], this); callbackfn.call(thisArg, this._hormigas_ObjectSet_elements[p]);
} }
} }
}; };
...@@ -1461,7 +1448,7 @@ Calls `callbackfn` for each element of the set. ...@@ -1461,7 +1448,7 @@ Calls `callbackfn` for each element of the set.
var two = {value: 2}; var two = {value: 2};
var three = {value: 3}; var three = {value: 3};
var set = new hormigas.ObjectSet(one, two, three); var set = new hormigas.ObjectSet(one, two, three);
set.every(function(element, set) { set.every(function(element) {
return element.value < 2; return element.value < 2;
}); // false }); // false
...@@ -1476,7 +1463,7 @@ Calls `callbackfn` for each element of the set. ...@@ -1476,7 +1463,7 @@ Calls `callbackfn` for each element of the set.
var thisArg = arguments[1]; var thisArg = arguments[1];
for (var p in this._hormigas_ObjectSet_elements) { for (var p in this._hormigas_ObjectSet_elements) {
if (Object.prototype.hasOwnProperty.call(this._hormigas_ObjectSet_elements, p) && if (Object.prototype.hasOwnProperty.call(this._hormigas_ObjectSet_elements, p) &&
!callbackfn.call(thisArg, this._hormigas_ObjectSet_elements[p], this)) { !callbackfn.call(thisArg, this._hormigas_ObjectSet_elements[p])) {
return false; return false;
} }
} }
...@@ -1491,7 +1478,7 @@ Calls `callbackfn` for each element of the set. ...@@ -1491,7 +1478,7 @@ Calls `callbackfn` for each element of the set.
var two = {value: 2}; var two = {value: 2};
var three = {value: 3}; var three = {value: 3};
var set = new hormigas.ObjectSet(one, two, three); var set = new hormigas.ObjectSet(one, two, three);
set.some(function(element, set) { set.some(function(element) {
return element.value < 2; return element.value < 2;
}); // true }); // true
...@@ -1506,7 +1493,7 @@ Calls `callbackfn` for each element of the set. ...@@ -1506,7 +1493,7 @@ Calls `callbackfn` for each element of the set.
var thisArg = arguments[1]; var thisArg = arguments[1];
for (var p in this._hormigas_ObjectSet_elements) { for (var p in this._hormigas_ObjectSet_elements) {
if (Object.prototype.hasOwnProperty.call(this._hormigas_ObjectSet_elements, p) && if (Object.prototype.hasOwnProperty.call(this._hormigas_ObjectSet_elements, p) &&
callbackfn.call(thisArg, this._hormigas_ObjectSet_elements[p], this)) { callbackfn.call(thisArg, this._hormigas_ObjectSet_elements[p])) {
return true; return true;
} }
} }
...@@ -1561,78 +1548,12 @@ iterated in the set. ...@@ -1561,78 +1548,12 @@ iterated in the set.
accumulator = elements[0]; accumulator = elements[0];
} }
while (i < ilen) { while (i < ilen) {
accumulator = callbackfn.call(undefined, accumulator, elements[i], this); accumulator = callbackfn.call(undefined, accumulator, elements[i]);
i++; i++;
} }
return accumulator; return accumulator;
}; };
/**
Calls `callbackfn` for each element of the set. The values returned by `callbackfn`
are added to a new array. This new array is the value returned by map.
var alpha = {length: 5};
var beta = {length: 4};
var gamma = {length: 5};
var set = new hormigas.ObjectSet(alpha, beta, gamma);
set.map(function(element) {
return element.length;
}); // [5,5,4] or [5,4,5] or [4,5,5]
@param {function} callbackfn The function to call for each element in the set.
@param {Object} [thisArg] The object to use as the this object in calls to `callbackfn`.
@return {Array} The mapped values.
*/
hormigas.ObjectSet.prototype.map = function(callbackfn /*, thisArg */) {
var thisArg = arguments[1];
var result = [];
for (var p in this._hormigas_ObjectSet_elements) {
if (Object.prototype.hasOwnProperty.call(this._hormigas_ObjectSet_elements, p)) {
result.push(callbackfn.call(thisArg, this._hormigas_ObjectSet_elements[p], this));
}
}
return result;
};
/**
Calls callbackfn for each element of the set. If callbackfn returns true
for an element then that element is added to a new array. This new array
is the value returned by filter.
var alpha = {length: 5};
var beta = {length: 4};
var gamma = {length: 5};
var set = new hormigas.ObjectSet(alpha, beta, gamma);
set.filter(function(element) {
return element.length > 4;
}); // [alpha, gamma] or [gamma, alpha]
@param {function} callbackfn The function to call for each element in the set.
@param {object} [thisArg] The object to use as the this object in calls to `callbackfn`.
@return {Array} The filtered values.
*/
hormigas.ObjectSet.prototype.filter = function(callbackfn /*, thisArg */) {
var thisArg = arguments[1];
var result = [];
for (var p in this._hormigas_ObjectSet_elements) {
if (Object.prototype.hasOwnProperty.call(this._hormigas_ObjectSet_elements, p)) {
var element = this._hormigas_ObjectSet_elements[p];
if (callbackfn.call(thisArg, element, this)) {
result.push(element);
}
}
}
return result;
};
}()); }());
// insure prototype object is initialized properly // insure prototype object is initialized properly
...@@ -1668,12 +1589,11 @@ hormigas.ObjectSet.mixin = function(obj) { ...@@ -1668,12 +1589,11 @@ hormigas.ObjectSet.mixin = function(obj) {
}; };
/** /**
@license @license
Maria release candidate 6 - an MVC framework for JavaScript applications Maria 1.0.0
Copyright (c) 2013, Peter Michaux Copyright (c) 2013, Peter Michaux
All rights reserved. All rights reserved.
Licensed under the Simplified BSD License. Licensed under the Simplified BSD License.
https://github.com/petermichaux/maria/blob/master/LICENSE http://peter.michaux.ca/downloads/maria/1.0.0/LICENSE
*/ */
/** /**
...@@ -1696,7 +1616,9 @@ maria.create = (function() { ...@@ -1696,7 +1616,9 @@ maria.create = (function() {
function F() {} function F() {}
return function(obj) { return function(obj) {
F.prototype = obj; F.prototype = obj;
return new F(); obj = new F();
F.prototype = null;
return obj;
}; };
}()); }());
/** /**
...@@ -1754,9 +1676,7 @@ Add an event listener. ...@@ -1754,9 +1676,7 @@ Add an event listener.
See evento.on for description. See evento.on for description.
*/ */
maria.on = function() { maria.on = evento.on;
evento.on.apply(this, arguments);
};
/** /**
...@@ -1765,9 +1685,7 @@ Remove an event listener. ...@@ -1765,9 +1685,7 @@ Remove an event listener.
See evento.off for description. See evento.off for description.
*/ */
maria.off = function() { maria.off = evento.off;
evento.off.apply(this, arguments);
};
/** /**
...@@ -1776,9 +1694,20 @@ Purge an event listener of all its subscriptions. ...@@ -1776,9 +1694,20 @@ Purge an event listener of all its subscriptions.
See evento.purge for description. See evento.purge for description.
*/ */
maria.purge = function() { maria.purge = evento.purge;
evento.purge.apply(this, arguments); /**
};
See hijos.Leaf for description.
*/
maria.Leaf = hijos.Leaf;
/**
See hijos.Node for description.
*/
maria.Node = hijos.Node;
/** /**
A constructor function to create new model objects. A constructor function to create new model objects.
...@@ -1908,7 +1837,7 @@ with those elements. ...@@ -1908,7 +1837,7 @@ with those elements.
You can create an empty set model object. You can create an empty set model object.
var setModel = new maria.SetModel(); var setModel = new maria.SetModel();
What makes a set model object interesting in comparison to a set is What makes a set model object interesting in comparison to a set is
that a set model object is a model object that dispatches "change" that a set model object is a model object that dispatches "change"
...@@ -1916,7 +1845,7 @@ events when elements are added or deleted from the the set. ...@@ -1916,7 +1845,7 @@ events when elements are added or deleted from the the set.
var view = { var view = {
update: function(evt) { update: function(evt) {
alert(setModel.length + ' element(s) in the set.'); alert(setModel.size + ' element(s) in the set.');
} }
}; };
maria.on(setModel, 'change', view, 'update'); maria.on(setModel, 'change', view, 'update');
...@@ -1945,7 +1874,7 @@ You can check if an element is in the set. ...@@ -1945,7 +1874,7 @@ You can check if an element is in the set.
You can get the number of elements in the set. You can get the number of elements in the set.
setModel.length; // returns 2 setModel.size; // returns 2
An element can be deleted from the set. Removing it multiple times An element can be deleted from the set. Removing it multiple times
has no effect. The delete method returns true if the element is has no effect. The delete method returns true if the element is
...@@ -1970,9 +1899,9 @@ setModel.delete if old browsers are not supported by your application. ...@@ -1970,9 +1899,9 @@ setModel.delete if old browsers are not supported by your application.
You can empty a set in one call. The method returns true if any You can empty a set in one call. The method returns true if any
elements are removed from the set model object. elements are removed from the set model object.
setModel.empty(); // returns false, alpha and beta removed above. setModel.clear(); // returns false, alpha and beta removed above.
If the call to empty does delete elements from the set, all "change" If the call to `clear` does delete elements from the set, all "change"
event listeners are passed an event object with deletedTargets just event listeners are passed an event object with deletedTargets just
as for the delete method. as for the delete method.
...@@ -2005,14 +1934,6 @@ A set model object has some other handy methods. ...@@ -2005,14 +1934,6 @@ A set model object has some other handy methods.
return accumulator + element.name.length; return accumulator + element.name.length;
}, 0); // returns 9 }, 0); // returns 9
setModel.map(function(element) {
return element.name.length;
}); // returns [4, 5] or [5, 4]
setModel.filter(function(element) {
return element.name.length > 4;
}); // returns [alpha]
The order of the elements returned by toArray and the order of The order of the elements returned by toArray and the order of
iteration of the other methods is undefined as a set is an unordered iteration of the other methods is undefined as a set is an unordered
collection. Do not depend on any ordering that the current collection. Do not depend on any ordering that the current
...@@ -2029,19 +1950,16 @@ to accomplish the same. ...@@ -2029,19 +1950,16 @@ to accomplish the same.
}; };
checkit.TodosModel.prototype = maria.create(maria.SetModel.prototype); checkit.TodosModel.prototype = maria.create(maria.SetModel.prototype);
checkit.TodosModel.prototype.constructor = checkit.TodosModel; checkit.TodosModel.prototype.constructor = checkit.TodosModel;
checkit.TodosModel.prototype.getDone = function() {
return this.filter(function(todo) {
return todo.isDone();
});
};
checkit.TodosModel.prototype.getUndone = function() {
return this.filter(function(todo) {
return !todo.isDone();
});
};
checkit.TodosModel.prototype.isAllDone = function() { checkit.TodosModel.prototype.isAllDone = function() {
return this.length > 0 && return (this.size > 0) &&
(this.getDone().length === this.length); this.every(function(todo) {
return todo.isDone();
});
};
checkit.TodosModel.prototype.isAllUndone = function() {
return this.every(function(todo) {
return !todo.isDone();
});
}; };
checkit.TodosModel.prototype.markAllDone = function() { checkit.TodosModel.prototype.markAllDone = function() {
this.forEach(function(todo) { this.forEach(function(todo) {
...@@ -2054,7 +1972,13 @@ to accomplish the same. ...@@ -2054,7 +1972,13 @@ to accomplish the same.
}); });
}; };
checkit.TodosModel.prototype.deleteDone = function() { checkit.TodosModel.prototype.deleteDone = function() {
this['delete'].apply(this, this.getDone()); var doneTodos = [];
this.forEach(function(todo) {
if (todo.isDone()) {
doneTodos.push(todo);
}
});
this['delete'].apply(this, doneTodos);
}; };
Another feature of set model objects is that events dispatched on Another feature of set model objects is that events dispatched on
...@@ -2108,7 +2032,7 @@ maria.SetModel.prototype.add = function() { ...@@ -2108,7 +2032,7 @@ maria.SetModel.prototype.add = function() {
added.push(argument); added.push(argument);
if ((typeof argument.addEventListener === 'function') && if ((typeof argument.addEventListener === 'function') &&
(typeof argument.removeEventListener === 'function')) { (typeof argument.removeEventListener === 'function')) {
argument.addEventListener('destroy', this); argument.addEventListener('destroy', this);
} }
if ((typeof argument.addParentEventTarget === 'function') && if ((typeof argument.addParentEventTarget === 'function') &&
// want to know can remove later // want to know can remove later
...@@ -2168,7 +2092,7 @@ maria.SetModel.prototype['delete'] = function() { ...@@ -2168,7 +2092,7 @@ maria.SetModel.prototype['delete'] = function() {
Deletes all elements of the set. Deletes all elements of the set.
If the set is modified as a result of this empty request then a `change` If the set is modified as a result of this `clear` request then a `change`
event is dispatched on the set model object. event is dispatched on the set model object.
@override @override
...@@ -2176,9 +2100,9 @@ event is dispatched on the set model object. ...@@ -2176,9 +2100,9 @@ event is dispatched on the set model object.
@return {boolean} True if the set was modified. Otherwise false. @return {boolean} True if the set was modified. Otherwise false.
*/ */
maria.SetModel.prototype.empty = function() { maria.SetModel.prototype.clear = function() {
var deleted = this.toArray(); var deleted = this.toArray();
var result = hormigas.ObjectSet.prototype.empty.call(this); var result = hormigas.ObjectSet.prototype.clear.call(this);
if (result) { if (result) {
for (var i = 0, ilen = deleted.length; i < ilen; i++) { for (var i = 0, ilen = deleted.length; i < ilen; i++) {
var element = deleted[i]; var element = deleted[i];
...@@ -2202,14 +2126,14 @@ must be deleted from this set. This handler will do the delete. ...@@ -2202,14 +2126,14 @@ must be deleted from this set. This handler will do the delete.
@param {Object} event The event object. @param {Object} event The event object.
*/ */
maria.SetModel.prototype.handleEvent = function(ev) { maria.SetModel.prototype.handleEvent = function(evt) {
// If it is a destroy event being dispatched on the // If it is a destroy event being dispatched on the
// destroyed element then we want to remove it from // destroyed element then we want to remove it from
// this set. // this set.
if ((ev.type === 'destroy') && if ((evt.type === 'destroy') &&
(ev.currentTarget === ev.target)) { (evt.currentTarget === evt.target)) {
this['delete'](ev.target); this['delete'](evt.target);
} }
}; };
...@@ -2258,6 +2182,19 @@ getModelActions method. ...@@ -2258,6 +2182,19 @@ getModelActions method.
}; };
}; };
By overriding the `getModelActions` method, the view will only observe
the model's `change` event if you explicitely list it which is not done
above. If you want to observe the `squashed`, `squished`, *and* `change`
events then you need to write the following.
maria.View.prototype.getModelActions = function() {
return {
'change' : 'update' ,
'squashed': 'onSquashed',
'squished': 'onSquished'
};
};
When the model is set, if the view had a previous model then the view When the model is set, if the view had a previous model then the view
will unsubscribe from the events it subscribed to on the prevous model will unsubscribe from the events it subscribed to on the prevous model
when the previous model was set. when the previous model was set.
...@@ -2267,7 +2204,7 @@ A view has a controller. You can get the current controller. ...@@ -2267,7 +2204,7 @@ A view has a controller. You can get the current controller.
view.getController(); view.getController();
The view's controller is created lazily the first time the The view's controller is created lazily the first time the
getController method is called. The view's getController method is called. The view's
getDefaultControllerConstructor method returns the constructor function getDefaultControllerConstructor method returns the constructor function
to create the controller object and the getDefaultController actually to create the controller object and the getDefaultController actually
calls that constructor. Your application may redefine or override calls that constructor. Your application may redefine or override
...@@ -2331,7 +2268,7 @@ accomplish the same. ...@@ -2331,7 +2268,7 @@ accomplish the same.
@constructor @constructor
@extends hijos.Node @extends maria.Node
@param {maria.Model} [model] @param {maria.Model} [model]
...@@ -2339,12 +2276,12 @@ accomplish the same. ...@@ -2339,12 +2276,12 @@ accomplish the same.
*/ */
maria.View = function(model, controller) { maria.View = function(model, controller) {
hijos.Node.call(this); maria.Node.call(this);
this.setModel(model); this.setModel(model);
this.setController(controller); this.setController(controller);
}; };
maria.View.prototype = maria.create(hijos.Node.prototype); maria.View.prototype = maria.create(maria.Node.prototype);
maria.View.prototype.constructor = maria.View; maria.View.prototype.constructor = maria.View;
/* /*
...@@ -2362,7 +2299,7 @@ maria.View.prototype.destroy = function() { ...@@ -2362,7 +2299,7 @@ maria.View.prototype.destroy = function() {
this._controller.destroy(); this._controller.destroy();
this._controller = null; this._controller = null;
} }
hijos.Node.prototype.destroy.call(this); maria.Node.prototype.destroy.call(this);
}; };
/** /**
...@@ -2408,7 +2345,7 @@ maria.View.prototype.setModel = function(model) { ...@@ -2408,7 +2345,7 @@ maria.View.prototype.setModel = function(model) {
Returns a controller constructor function to be used to create Returns a controller constructor function to be used to create
a controller for this view. a controller for this view.
@return {function} The controller constructor function. @return {function} The controller constructor function.
*/ */
maria.View.prototype.getDefaultControllerConstructor = function() { maria.View.prototype.getDefaultControllerConstructor = function() {
...@@ -2496,6 +2433,10 @@ maria.View.prototype._setModelAndController = function(model, controller) { ...@@ -2496,6 +2433,10 @@ maria.View.prototype._setModelAndController = function(model, controller) {
} }
this._model = model; this._model = model;
} }
if ((this._controller !== controller) && this._controller) {
this._controller.setView(null);
this._controller.setModel(null);
}
if (controller) { if (controller) {
controller.setView(this); controller.setView(this);
controller.setModel(model); controller.setModel(model);
...@@ -2874,14 +2815,14 @@ By default Maria uses the Grail library as its DOM query engine. This is ...@@ -2874,14 +2815,14 @@ By default Maria uses the Grail library as its DOM query engine. This is
to support older browsers that do not have `querySelector`. The Grail to support older browsers that do not have `querySelector`. The Grail
engine only a limited set of simple selectors. engine only a limited set of simple selectors.
.class .class
tag tag
tag.class tag.class
#id #id
If your application only needs to work in newer browsers you can create If your application only needs to work in newer browsers then you can create
a Maria plugin to use `querySelector` but ensure the root element will a Maria plugin to use `querySelector`. Consider if you want the root element
be returned if it matches `selector`. to be returned if it matches `selector`.
If your application needs to work in older browsers but you need more If your application needs to work in older browsers but you need more
complex CSS `selector` strings then you can create a Maria plugin complex CSS `selector` strings then you can create a Maria plugin
...@@ -3170,7 +3111,8 @@ maria.Controller.prototype.getModel = function() { ...@@ -3170,7 +3111,8 @@ maria.Controller.prototype.getModel = function() {
/** /**
`setModel` is intended to be called **only** by **Pretend you do not know that this method even exists.**
`setModel` is intended to be called **only** by
the view `_setModelAndController` method. **Do otherwise the view `_setModelAndController` method. **Do otherwise
at your own risk!** at your own risk!**
...@@ -3194,7 +3136,8 @@ maria.Controller.prototype.getView = function() { ...@@ -3194,7 +3136,8 @@ maria.Controller.prototype.getView = function() {
/** /**
`setView` is intended to be called **only** by **Pretend you do not know that this method even exists.**
`setView` is intended to be called **only** by
the view `_setModelAndController` method. **Do otherwise the view `_setModelAndController` method. **Do otherwise
at your own risk!** at your own risk!**
...@@ -3256,19 +3199,16 @@ for maria.SetModel. ...@@ -3256,19 +3199,16 @@ for maria.SetModel.
maria.SetModel.subclass(checkit, 'TodosModel', { maria.SetModel.subclass(checkit, 'TodosModel', {
properties: { properties: {
getDone: function() {
return this.filter(function(todo) {
return todo.isDone();
});
},
getUndone: function() {
return this.filter(function(todo) {
return !todo.isDone();
});
},
isAllDone: function() { isAllDone: function() {
return this.length > 0 && return (this.size > 0) &&
(this.getDone().length === this.length); this.every(function(todo) {
return todo.isDone();
});
},
isAllUndone: function() {
return this.every(function(todo) {
return !todo.isDone();
});
}, },
markAllDone: function() { markAllDone: function() {
this.forEach(function(todo) { this.forEach(function(todo) {
...@@ -3281,7 +3221,13 @@ for maria.SetModel. ...@@ -3281,7 +3221,13 @@ for maria.SetModel.
}); });
}, },
deleteDone: function() { deleteDone: function() {
this['delete'].apply(this, this.getDone()); var doneTodos = [];
this.forEach(function(todo) {
if (todo.isDone()) {
doneTodos.push(todo);
}
});
this['delete'].apply(this, doneTodos);
} }
} }
}); });
...@@ -3526,3 +3472,5 @@ the documentation for maria.Controller. ...@@ -3526,3 +3472,5 @@ the documentation for maria.Controller.
maria.Controller.subclass = function() { maria.Controller.subclass = function() {
maria.subclass.apply(this, arguments); maria.subclass.apply(this, arguments);
}; };
return maria;}()); // IIFE
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
<script src="bower_components/todomvc-common/base.js"></script> <script src="bower_components/todomvc-common/base.js"></script>
<script src="bower_components/director/build/director.js"></script> <script src="bower_components/director/build/director.js"></script>
<script src="lib/maria/maria.js"></script> <script src="bower_components/maria-bower/maria.js"></script>
<script src="lib/aristocrat/aristocrat.js"></script> <script src="bower_components/aristocrat-bower/aristocrat.js"></script>
<script src="js/namespace.js"></script> <script src="js/namespace.js"></script>
<script src="js/util.js"></script> <script src="js/util.js"></script>
......
...@@ -30,19 +30,31 @@ maria.SetModel.subclass(checkit, 'TodosModel', { ...@@ -30,19 +30,31 @@ maria.SetModel.subclass(checkit, 'TodosModel', {
}, },
getCompleted: function () { getCompleted: function () {
return this.filter(function (todo) { var completeTodos = [];
return todo.isCompleted(); this.forEach(function (todo) {
if (todo.isCompleted()) {
completeTodos.push(todo);
}
}); });
return completeTodos;
}, },
getIncompleted: function () { getIncompleted: function () {
return this.filter(function (todo) { var incompleteTodos = [];
return !todo.isCompleted(); this.forEach(function (todo) {
if (!todo.isCompleted()) {
incompleteTodos.push(todo);
}
}); });
return incompleteTodos;
}, },
isAllCompleted: function () { isAllCompleted: function () {
return (this.length > 0) && (this.getCompleted().length === this.length); return (this.size > 0) && (this.getCompleted().length === this.size);
},
isEmpty: function () {
return this.size === 0;
}, },
markAllCompleted: function () { markAllCompleted: function () {
...@@ -62,9 +74,11 @@ maria.SetModel.subclass(checkit, 'TodosModel', { ...@@ -62,9 +74,11 @@ maria.SetModel.subclass(checkit, 'TodosModel', {
}, },
toJSON: function () { toJSON: function () {
return this.map(function (todo) { var todoJSON = [];
return todo.toJSON(); this.forEach(function (todo) {
todoJSON.push(todo.toJSON());
}); });
return todoJSON;
} }
} }
}); });
......
...@@ -12,7 +12,7 @@ maria.SetView.subclass(checkit, 'TodosAppView', { ...@@ -12,7 +12,7 @@ maria.SetView.subclass(checkit, 'TodosAppView', {
buildData: function () { buildData: function () {
var model = this.getModel(); var model = this.getModel();
var length = model.length; var length = model.size;
this.find('#main').style.display = (length > 0) ? '' : 'none'; this.find('#main').style.display = (length > 0) ? '' : 'none';
this.find('#footer').style.display = (length > 0) ? '' : 'none'; this.find('#footer').style.display = (length > 0) ? '' : 'none';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment