Last active
February 29, 2016 08:32
-
-
Save poteto/f857fbc4e65c5f717114 to your computer and use it in GitHub Desktop.
test pipe
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
import Ember from 'ember'; | |
const { Controller } = Ember; | |
export default Controller.extend({ | |
init() { | |
this._super(...arguments); | |
this.cart = [ | |
{ id: 0, name: 'Socks', price: 5 }, | |
{ id: 1, name: 'Shoes', price: 50 } | |
]; | |
this.item = { | |
id: 2, | |
name: 'Dog Treats', | |
price: 12 | |
} | |
} | |
}); |
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
import Ember from 'ember'; | |
export function append([b, a]/*, hash*/) { | |
let arity = arguments[0].length; | |
if (arity === 2) { | |
return [...a, ...b]; | |
} | |
if (arity === 1) { | |
return function(curried) { | |
b.pushObject(curried); | |
return b; | |
} | |
} | |
} | |
export default Ember.Helper.helper(append); |
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
import Ember from 'ember'; | |
export function curryConcat([b, a]/*, hash*/) { | |
let arity = arguments[0].length; | |
if (arity === 2) { | |
return a.concat(b); | |
} | |
if (arity === 1) { | |
return function(curried) { | |
return b.concat(curried); | |
}; | |
} | |
} | |
export default Ember.Helper.helper(curryConcat); |
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
import Ember from 'ember'; | |
const { Helper: { helper } } = Ember; | |
export function pipe(actions = []) { | |
return function(...args) { | |
return actions.reduce((acc, curr, idx) => { | |
if (idx === 0) { | |
return curr(...args); | |
} | |
return curr(acc); | |
}, undefined); | |
}; | |
} | |
export default helper(pipe); |
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
import Ember from 'ember'; | |
const { get, isEmpty } = Ember; | |
function _reduce(key, array) { | |
array = isEmpty(array) ? [] : array; | |
return array.reduce((acc, item) => { | |
return acc + get(item, key); | |
}, 0); | |
} | |
export function reduceBy([reduceByKey, array]/*, hash*/) { | |
let arity = arguments[0].length; | |
if (arity === 2) { | |
return _reduce(reduceByKey, array); | |
} | |
if (arity === 1) { | |
return function(curried) { | |
return _reduce(reduceByKey, curried); | |
} | |
} | |
} | |
export default Ember.Helper.helper(reduceBy); |
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
{ | |
"version": "0.6.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.3.1/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.3.3/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment