-
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 #128 - DockYard:closure-actionify, r=poteto
Create closure action form of action helpers - `pipe-action` helper - `toggle-action` helper
- Loading branch information
Showing
11 changed files
with
105 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Ember from 'ember'; | ||
|
||
const ClosureActionModule = Ember.__loader.require('ember-routing-htmlbars/keywords/closure-action'); | ||
|
||
export default ClosureActionModule.ACTION; |
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,8 @@ | ||
import { helper } from 'ember-helper'; | ||
import { pipe } from './pipe'; | ||
import ACTION from '../-private/closure-action'; | ||
|
||
const closurePipe = pipe; | ||
closurePipe[ACTION] = true; | ||
|
||
export default helper(closurePipe); |
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,8 @@ | ||
import { helper } from 'ember-helper'; | ||
import { toggle } from './toggle'; | ||
import ACTION from '../--private/closure-action'; | ||
|
||
const closureToggle = toggle; | ||
closureToggle[ACTION] = true; | ||
|
||
export default helper(closureToggle); |
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 @@ | ||
export { default } from 'ember-composable-helpers/helpers/pipe-action'; |
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 } from 'ember-composable-helpers/helpers/toggle-action'; |
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,3 @@ | ||
<button {{action calculate 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,3 @@ | ||
<button {{action toggleAction}}> | ||
Toggle | ||
</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,25 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
moduleForComponent('pipe-action', 'Integration | Helper | {{pipe-action}}', { | ||
integration: true | ||
}); | ||
|
||
test('it can be used as a closure action', function(assert) { | ||
let value = 0; | ||
this.on('add', (x, y) => x + y); | ||
this.on('square', (x) => x * x); | ||
this.on('squareRoot', (x) => value = Math.sqrt(x)); | ||
this.render(hbs` | ||
{{perform-calculation | ||
calculate=(pipe-action | ||
(action "add") | ||
(action "square") | ||
(action "squareRoot")) | ||
}} | ||
`); | ||
|
||
assert.equal(value, '0', 'precond - should render 0'); | ||
this.$('button').click(); | ||
assert.equal(value, '6', 'should render 6'); | ||
}); |
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,18 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
moduleForComponent('toggle-action', 'Integration | Helper | {{toggle-action}}', { | ||
integration: true | ||
}); | ||
|
||
test('it can be used as a closure action', function(assert) { | ||
this.set('isExpanded', false); | ||
this.render(hbs` | ||
<p>{{if isExpanded "I am expanded" "I am not"}}</p> | ||
{{toggle-button toggleAction=(toggle "isExpanded" this)}} | ||
`); | ||
|
||
this.$('button').click(); | ||
|
||
assert.equal(this.$('p').text().trim(), 'I am expanded', 'should be expanded'); | ||
}); |