Permalink
Browse files

reverse arg order of can.each

  • Loading branch information...
justinbmeyer committed Apr 6, 2012
1 parent 4d6102e commit 234fd3b9eca18abdbc3fdbea114be6a818bfe6e3
View
@@ -582,7 +582,7 @@ steal('can/construct', function( $ ) {
*/
off : function(){
var el = this.element[0]
- each(this._bindings || [], function( key, value ) {
+ each(this._bindings || [], function( value ) {
value(el);
});
// Adds bindings.
@@ -721,7 +721,7 @@ steal('can/construct', function( $ ) {
each(["change", "click", "contextmenu", "dblclick", "keydown", "keyup",
"keypress", "mousedown", "mousemove", "mouseout", "mouseover",
"mouseup", "reset", "resize", "scroll", "select", "submit", "focusin",
- "focusout", "mouseenter", "mouseleave"], function( i, v ) {
+ "focusout", "mouseenter", "mouseleave"], function( v ) {
processors[v] = basicProcessor;
});
View
@@ -486,13 +486,13 @@ steal('can/observe',function(){
}
var self = this;
- can.each(ajaxMethods, function(name, method){
+ can.each(ajaxMethods, function(method, name){
if ( ! can.isFunction( self[name] )) {
self[name] = ajaxMaker(method, self[name]);
}
});
var clean = can.proxy(this._clean, self);
- can.each({findAll : "models", findOne: "model"}, function(name, method){
+ can.each({findAll : "models", findOne: "model"}, function(method, name){
var old = self[name];
can.Construct._overwrite(self, base, name, function(params, success, error){
@@ -642,12 +642,12 @@ steal('can/observe',function(){
}
//!steal-remove-end
- can.each(raw, function( i, rawPart ) {
+ can.each(raw, function( rawPart ) {
res.push( self.model( rawPart ));
});
if ( ! arr ) { // Push other stuff onto `array`.
- can.each(instancesRawData, function(prop, val){
+ can.each(instancesRawData, function(val, prop){
if ( prop !== 'data' ) {
res[prop] = val;
}
@@ -1036,7 +1036,7 @@ steal('can/observe',function(){
* - Removes the model from the global list if its used.
*
*/
- "destroyed"], function( i, funcName ) {
+ "destroyed"], function( funcName ) {
can.Model.prototype[funcName] = function( attrs ) {
var stub,
constructor = this.constructor;
@@ -95,7 +95,7 @@
Contact.findAll({},function(contacts){
var contactsEl = can.$('#contacts');
- can.each(contacts, function(i, contact){
+ can.each(contacts, function(contact){
var li = can.$('<li>')
.html(contact.name + " "+ contact.ageThisYear())
.appendTo(contactsEl);
@@ -1,6 +1,6 @@
steal('can/observe', function(){
-can.each([ can.Observe, can.Model ], function(i,clss){
+can.each([ can.Observe, can.Model ], function(clss){
// in some cases model might not be defined quite yet.
if(clss === undefined){
return;
@@ -187,13 +187,13 @@ can.each([ can.Observe, can.Model ], function(i,clss){
var self = this;
oldSetup.call(self, superClass, stat, proto);
- can.each(["attributes", "validations"], function( i, name ) {
+ can.each(["attributes", "validations"], function( name ) {
if (!self[name] || superClass[name] === self[name] ) {
self[name] = {};
}
});
- can.each(["convert", "serialize"], function( i, name ) {
+ can.each(["convert", "serialize"], function( name ) {
if ( superClass[name] != self[name] ) {
self[name] = can.extend({}, superClass[name], self[name]);
}
@@ -271,7 +271,7 @@ can.Observe.prototype.serialize = function(attrName){
attrs = this.__get();
}
- can.each(attrs, function( name, val ) {
+ can.each(attrs, function( val, name ) {
var type = Class.attributes[name],
converter= Class.serialize[type];
@@ -114,7 +114,7 @@ <h1>Observe Backup Demo</h1>
Contact.findAll({},function(contacts){
var contactsEl = can.$('#contacts');
- can.each(contacts, function(i, contact){
+ can.each(contacts, function(contact){
// add the contact to the page
var li = can.$('<li>')
View
@@ -11,7 +11,7 @@ steal('can/construct', function() {
// Removes all listeners.
unhookup = function(items, namespace){
- return can.each(items, function(i, item){
+ return can.each(items, function(item){
if(item && item.unbind){
item.unbind("change" + namespace);
}
@@ -97,7 +97,7 @@ steal('can/construct', function() {
var items = collecting.slice(0);
collecting = undefined;
batchNum++;
- can.each(items, function( i, item) {
+ can.each(items, function( item ) {
can.trigger.apply(can, item)
})
@@ -108,7 +108,7 @@ steal('can/construct', function() {
// `where` - To put properties, in an `{}` or `[]`.
serialize = function( observe, how, where ) {
// Go through each property.
- observe.each(function( name, val ) {
+ observe.each(function( val, name ) {
// If the value is an `object`, and has an `attrs` or `serialize` function.
where[name] = canMakeObserve(val) && can.isFunction( val[how] ) ?
// Call `attrs` or `serialize` to get the original data back.
@@ -351,7 +351,7 @@ steal('can/construct', function() {
* with each attribute name and value.
*
* new Observe({ foo: 'bar' })
- * .each( function( name, value ) {
+ * .each( function( value, name ) {
* equals( name, 'foo' );
* equals( value,'bar' );
* });
@@ -363,7 +363,7 @@ steal('can/construct', function() {
* log 3:
*
* new Observe({ a: 1, b: 2, c: 3 })
- * .each( function( name, value ) {
+ * .each( function( value, name ) {
* console.log(value);
* if ( name == 2 ) {
* return false;
@@ -629,7 +629,7 @@ steal('can/construct', function() {
self = this,
newVal;
- this.each(function(prop, curVal){
+ this.each(function(curVal, prop){
newVal = props[prop];
// If we are merging...
@@ -843,19 +843,19 @@ steal('can/construct', function() {
* with each index and value.
*
* new Observe.List(['a'])
- * .each(function(index, value){
+ * .each(function( value , index ){
* equals(index, 1)
* equals(value,'a')
* })
*
- * @param {function} handler(index,value) A function that will get
+ * @param {function} handler(value,index) A function that will get
* called back with the index and value of each item on the list.
*
* Returning `false` breaks the looping. The following will never
* log 'c':
*
* new Observe(['a','b','c'])
- * .each(function(index, value){
+ * .each(function(value, index){
* console.log(value)
* if(index == 1){
* return false;
@@ -1124,7 +1124,7 @@ steal('can/construct', function() {
// Adds a method
// `name` - The method name.
// `where` - Where items in the `array` should be added.
- function( name, where ) {
+ function( where, name ) {
list.prototype[name] = function() {
// Get the items being added.
var args = getArgs(arguments),
@@ -1192,7 +1192,7 @@ steal('can/construct', function() {
shift: 0
},
// Creates a `remove` type method
- function( name, where ) {
+ function( where, name ) {
list.prototype[name] = function() {
var args = getArgs(arguments),
View
@@ -111,7 +111,7 @@ can.each({
// adds a method where
// - name - method name
// - where - where items in the array should be added
-function( name, where ) {
+function( where , name ) {
var proto = can.Observe.List.prototype,
old = proto[name];
@@ -18,7 +18,7 @@ var validate = function(attrNames, options, proc) {
}
var self = this;
- can.each(attrNames, function(i, attrName) {
+ can.each(attrNames, function(attrName) {
// Add a test function for each attribute
if(!self.validations[attrName]){
self.validations[attrName] = [];
@@ -59,7 +59,7 @@ can.Observe.prototype.__set = function(prop, value, current, success, error){
return this;
}
-can.each([ can.Observe, can.Model ], function(i,clss){
+can.each([ can.Observe, can.Model ], function(clss){
// in some cases model might not be defined quite yet.
if(clss === undefined){
return;
@@ -331,7 +331,7 @@ can.extend(can.Observe.prototype, {
// attr - the name of the attribute
// funcs - the validation functions
addErrors = function( attr, funcs ) {
- can.each(funcs, function( i, func ) {
+ can.each(funcs, function( func ) {
var res = func.call(self, isTest ? ( self.__convert ?
self.__convert(attr,newVal) :
newVal ): self[attr]);
@@ -349,7 +349,7 @@ can.extend(can.Observe.prototype, {
// go through each attribute or validation and
// add any errors
- can.each(attrs || validations || {}, function( attr, funcs ) {
+ can.each(attrs || validations || {}, function( funcs, attr ) {
// if we are iterating through an array, use funcs
// as the attr name
if ( typeof attr == 'number' ) {
View
@@ -102,7 +102,7 @@ steal('can/observe', 'can/util/string/deparam', function() {
// If we have a route name in our `can.route` data, use it.
if ( ! ( routeName && (route = can.route.routes[routeName]))){
// Otherwise find route.
- each(can.route.routes, function(name, temp){
+ each(can.route.routes, function(temp, name){
matchCount = matchesData(temp, data);
if ( matchCount > matches ) {
route = temp;
@@ -122,7 +122,7 @@ steal('can/observe', 'can/util/string/deparam', function() {
}),
after;
// Remove matching default values
- each(route.defaults, function(name,val){
+ each(route.defaults, function(val,name){
if(cpy[name] === val) {
delete cpy[name]
}
@@ -174,7 +174,7 @@ steal('can/observe', 'can/util/string/deparam', function() {
var route = {
length: -1
};
- each(can.route.routes, function(name, temp){
+ each(can.route.routes, function(temp, name){
if ( temp.test.test(url) && temp.length > route.length ) {
route = temp;
}
@@ -195,7 +195,7 @@ steal('can/observe', 'can/util/string/deparam', function() {
obj = extend(true, {}, route.defaults, obj);
// Overwrite each of the default values in `obj` with those in
// parts if that part is not empty.
- each(parts,function(i, part){
+ each(parts,function(part, i){
if ( part && part !== '&') {
obj[route.names[i]] = decodeURIComponent( part );
}
@@ -362,7 +362,7 @@ steal('can/observe', 'can/util/string/deparam', function() {
// The functions in the following list applied to `can.route` (e.g. `can.route.attr('...')`) will
// instead act on the `can.route.data` observe.
- each(['bind','unbind','delegate','undelegate','attr','removeAttr'], function(i, name){
+ each(['bind','unbind','delegate','undelegate','attr','removeAttr'], function(name){
can.route[name] = function(){
return can.route.data[name].apply(can.route.data, arguments)
}
View
@@ -0,0 +1,14 @@
+steal(function(){
+ can.each = function(elements, callback) {
+ var i = 0, key;
+ if (typeof elements.length == 'number' && elements.pop)
+ for(var len = elements.length; i < len; i++) {
+ if(callback(elements[i], i, elements) === false) return elements;
+ }
+ else
+ for(key in elements) {
+ if(callback(elements[key], key) === false) return elements;
+ }
+ return elements;
+ }
+})
View
@@ -36,7 +36,7 @@ steal(function(){
// needs to be resolved.
rp = [];
- can.each(args, function(j, arg){
+ can.each(args, function(arg, j){
arg.done(function() {
rp[j] = (arguments.length < 2) ? arguments[0] : arguments;
if (++done == args.length) {
@@ -63,7 +63,7 @@ steal(function(){
var self = this;
// In Safari, the properties of the `arguments` object are not enumerable,
// so we have to convert arguments to an `Array` that allows `can.each` to loop over them.
- can.each(Array.prototype.slice.call(arguments), function( i, v, args ) {
+ can.each(Array.prototype.slice.call(arguments), function( v, i, args ) {
if ( ! v )
return;
if ( v.constructor === Array ) {
@@ -143,7 +143,7 @@ steal(function(){
this._status = st;
- can.each(dst, function(i, d){
+ can.each(dst, function(d){
d.apply(context, args);
});
View
@@ -31,7 +31,7 @@ steal('can/util').then(function() {
var oldClean = $.cleanData;
can.cleanData = function( elems ) {
- can.each( elems, function( i, elem ) {
+ can.each( elems, function( elem ) {
can.$(elem).triggerHandler("destroyed");
});
oldClean(elems);
View
@@ -3,6 +3,7 @@ steal({
_skip: true
}, '../event.js').then(
'./trigger',
+ 'can/util/array/each.js',
function(){
// dojo.js
@@ -30,18 +31,6 @@ steal({
can.map = function(arr, fn){
return dojo.map(can.makeArray(arr||[]), fn);
};
- can.each = function(elements, callback) {
- var i, key;
- if (typeof elements.length == 'number' && elements.pop)
- for(i = 0; i < elements.length; i++) {
- if(callback(i, elements[i]) === false) return elements;
- }
- else
- for(key in elements) {
- if(callback(key, elements[key]) === false) return elements;
- }
- return elements;
- }
// Map object helpers.
can.extend = function(first){
if(first === true){
View
@@ -45,7 +45,7 @@ can.dispatch = function(event){
self= this,
args = [event].concat(event.data || []);
- can.each(handlers, function(i, ev){
+ can.each(handlers, function(ev){
event.data = args.slice(1);
ev.handler.apply(self, args);
});
Oops, something went wrong.

0 comments on commit 234fd3b

Please sign in to comment.