Skip to content

Commit

Permalink
Use native Array.isArray when available(tx to Ori Avtalion) and force…
Browse files Browse the repository at this point in the history
… false value only for loop filter.
  • Loading branch information
beebole committed Apr 17, 2010
1 parent 12ac5c0 commit 003ec00
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
19 changes: 10 additions & 9 deletions libs/pure.js
Expand Up @@ -7,7 +7,7 @@
Copyright (c) 2010 Michael Cvilic - BeeBole.com
Thanks to Rog Peppe for the functional JS jump
revision: 2.43
revision: 2.44
*/

var $p, pure = $p = function(){
Expand Down Expand Up @@ -56,7 +56,14 @@ $p.core = function(sel, ctxt, plugins){
IMG:'src',
INPUT:'value'
},
isArray;
// check if the argument is an array - thanks salty-horse (Ori Avtalion)
isArray = Array.isArray ?
function(o) {
return Array.isArray(o);
} :
function(o) {
return Object.prototype.toString.call(o) === "[object Array]";
};

return plugins;

Expand Down Expand Up @@ -106,12 +113,6 @@ $p.core = function(sel, ctxt, plugins){
return h;
})(node);
}

// check if the argument is an array
function isArray(o) {
return Object.prototype.toString.call( o ) === "[object Array]";
};


// returns the string generator function
function wrapquote(qfn, f){
Expand Down Expand Up @@ -356,7 +357,7 @@ $p.core = function(sel, ctxt, plugins){
//if array, set a length property - filtered items
typeof len !== 'undefined' && (ctxt.length = len);
//if filter directive
if(typeof ftr === 'function' && !ftr(ctxt)){
if(typeof ftr === 'function' && ftr(ctxt) === false){
filtered++;
return;
}
Expand Down
4 changes: 2 additions & 2 deletions libs/pure_packed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tutorial/tuto5.html
Expand Up @@ -13,10 +13,10 @@
<script>
var data = {
animals:[
{name:'bird'},
{name:'mouse'},
{name:'cat'},
{name:'dog'},
{name:'mouse'}
{name:'bird'},
{name:'dog'}
]
};

Expand Down
2 changes: 2 additions & 0 deletions tutorial/tuto5b.html
Expand Up @@ -27,10 +27,12 @@
'animal<-animals':{
'.':'animal.name'
},
//sort function like the ususal Array.sort
sort:function(a, b){
return a.name > b.name ? 1 : -1;
},
filter:function(a){
//if the returned value is false, the rendering will be skipped for this entry
return a.context.legs === a.item.legs;
}
}
Expand Down

0 comments on commit 003ec00

Please sign in to comment.