From 1874ad2f7b40f5c16e1f2406c5f224a32a031c0e Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Thu, 15 Aug 2013 22:45:44 -0400 Subject: [PATCH] add notes; rearrange item.js --- item.js | 32 ++++++++++++++------------------ notes.md | 10 ++++++++++ 2 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 notes.md diff --git a/item.js b/item.js index 4a2fe36..c6bf7f1 100644 --- a/item.js +++ b/item.js @@ -75,28 +75,12 @@ function mungeSorter( sorter ) { } var args = trim( sorter ).split(' '); - var parser; - - // use second argument as a parser - switch ( args[1] ) { - case 'parseInt' : - parser = function( val ) { - return parseInt( val, 10 ); - }; - break; - case 'parseFloat' : - parser = function( val ) { - return parseFloat( val ); - }; - } var query = args[0]; + // check if query looks like [an-attribute] var attrMatch = query.match( /^\[(.+)\]$/ ); var attr = attrMatch && attrMatch[1]; - - var getValue; - // if query looks like [foo-bar], get attribute if ( attr ) { getValue = function( elem ) { @@ -108,7 +92,19 @@ function mungeSorter( sorter ) { return getText( elem.querySelector( query ) ); }; } - + // use second argument as a parser + var parser; + switch ( args[1] ) { + case 'parseInt' : + parser = function( val ) { + return parseInt( val, 10 ); + }; + break; + case 'parseFloat' : + parser = function( val ) { + return parseFloat( val ); + }; + } // parse the value, if there was a parser sorter = parser ? function( elem ) { return parser( getValue( elem ) ); diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..ff37c86 --- /dev/null +++ b/notes.md @@ -0,0 +1,10 @@ +sortBy an array + +sortBy the history + +getSortData shorthand + +filter + +filter on init doesn't do transition +