Created
March 20, 2013 19:23
-
-
Save leepfrog/5207638 to your computer and use it in GitHub Desktop.
SortPipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Blocks.SortPipePlugin = Em.PipePlugin.extend | |
| # Define a list of sorting properties | |
| observes: Em.computed.alias('sortProperties') | |
| # The sorting function to use | |
| sortFunction: Em.compare | |
| # Our sort routine | |
| process: (inputArr) -> | |
| # DS.ManyArray does not support sort() | |
| inputArr = inputArr.toArray() if inputArr.constructor == DS.ManyArray | |
| inputArr.sort (obj1, obj2) => | |
| retVal = 0 | |
| props = @get('observes').slice(0) | |
| while retVal == 0 && props.length > 0 | |
| sortProperty = props.shift() | |
| retVal = @get('sortFunction')( obj1.get(sortProperty), obj2.get(sortProperty), sortProperty) | |
| return retVal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment