-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #1 - DockYard:compose, r=poteto
Initial work on compose helper None
- Loading branch information
Showing
15 changed files
with
192 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Ember from 'ember'; | ||
|
||
const { Helper: { helper } } = Ember; | ||
|
||
export function compose([f, g]) { | ||
return function(...args) { | ||
return f(g(...args)); | ||
}; | ||
} | ||
|
||
export default helper(compose); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as ComposeHelper } from './helpers/compose'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, compose } from 'ember-functional-helpers/helpers/compose'; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "ember-functional-helpers", | ||
"version": "0.0.0", | ||
"description": "The default blueprint for ember-cli addons.", | ||
"description": "Functional helpers for Ember", | ||
"directories": { | ||
"doc": "doc", | ||
"test": "tests" | ||
|
@@ -11,11 +11,16 @@ | |
"start": "ember server", | ||
"test": "ember try:testall" | ||
}, | ||
"repository": "", | ||
"repository": "https://github.com/DockYard/ember-functional-helpers", | ||
"bugs": "https://github.com/DockYard/ember-functional-helpers/issues", | ||
"homepage": "https://github.com/DockYard/ember-functional-helpers", | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
}, | ||
"author": "", | ||
"author": [ | ||
"Lauren Tan <[email protected]>", | ||
"Marten Schilstra <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"devDependencies": { | ||
"broccoli-asset-rev": "^2.2.0", | ||
|
@@ -30,7 +35,6 @@ | |
"ember-cli-release": "0.2.8", | ||
"ember-cli-sri": "^2.0.0", | ||
"ember-cli-uglify": "^1.2.0", | ||
"ember-data": "^2.3.0", | ||
"ember-disable-prototype-extensions": "^1.1.0", | ||
"ember-disable-proxy-controllers": "^1.0.1", | ||
"ember-export-application-global": "^1.0.4", | ||
|
@@ -40,7 +44,9 @@ | |
"loader.js": "^4.0.0" | ||
}, | ||
"keywords": [ | ||
"ember-addon" | ||
"ember-addon", | ||
"functional helpers", | ||
"compose" | ||
], | ||
"dependencies": { | ||
"ember-cli-babel": "^5.1.5" | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { test } from 'qunit'; | ||
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | ||
|
||
moduleForAcceptance('Acceptance | compose'); | ||
|
||
test('it composes actions', function(assert) { | ||
visit('/compose'); | ||
|
||
andThen(() => assert.equal(currentURL(), '/compose', 'correct url')); | ||
andThen(() => click('#compose-button')); | ||
andThen(() => { | ||
assert.ok(find('pre:contains("Value: 36")').length, 'it returns the right value'); | ||
}); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Ember from 'ember'; | ||
|
||
const { Controller, set } = Ember; | ||
|
||
export default Controller.extend({ | ||
value: 0, | ||
|
||
actions: { | ||
add(x, y) { | ||
return x + y; | ||
}, | ||
|
||
square(x) { | ||
return set(this, 'value', x * x); | ||
} | ||
} | ||
}); |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<pre>Value: {{value}}</pre> | ||
|
||
<button | ||
id="compose-button" | ||
{{action (compose square add) 2 4}}> | ||
Calculate | ||
</button> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div class="add-and-square"> | ||
{{add-and-square | ||
value=value | ||
add=(action "add") | ||
square=(action "square") | ||
}} | ||
</div> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { compose } from 'dummy/helpers/compose'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Helper | compose'); | ||
|
||
function add(x, y) { | ||
return x + y; | ||
} | ||
|
||
function square(x) { | ||
return x * x; | ||
} | ||
|
||
test('it composes two functions', function(assert) { | ||
let composed = compose([square, add]); | ||
let result = composed(2, 4); | ||
|
||
assert.equal(result, 36, 'it composes two functions'); | ||
}); |