-
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.
* Introduce pick object helper * Alphabetize object helpers in README
- Loading branch information
1 parent
9eb2030
commit 1d4a32a
Showing
4 changed files
with
123 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import { get } from '@ember/object'; | ||
|
||
export default helper(function event([path, action]/*, hash*/) { | ||
return function(event) { | ||
let value = get(event, path); | ||
|
||
if (!action) { | ||
return value; | ||
} | ||
|
||
action(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 @@ | ||
export { default, pick } from 'ember-composable-helpers/helpers/pick'; |
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,44 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { click, render } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
module('Integration | Helper | pick', function(hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test("Works when used with {{on}} modifier and pipe", async function(assert) { | ||
assert.expect(1); | ||
|
||
this.set('onFocus', function(value) { | ||
assert.equal(value, 'pizza party', 'The action receives the correct value'); | ||
}) | ||
|
||
await render(hbs` | ||
<input | ||
id="test-input" | ||
value="pizza party" | ||
{{on 'focusin' (pipe (pick 'target.value') this.onFocus)}} | ||
/> | ||
`); | ||
|
||
await click('#test-input'); | ||
}); | ||
|
||
test("Shorthand works when used with {{on}} modifier and optional action is provided", async function(assert) { | ||
assert.expect(1); | ||
|
||
this.set('onFocus', function(value) { | ||
assert.equal(value, 'pizza party', 'The action receives the correct value'); | ||
}) | ||
|
||
await render(hbs` | ||
<input | ||
id="test-input" | ||
value="pizza party" | ||
{{on 'focusin' (pick 'target.value' this.onFocus)}} | ||
/> | ||
`); | ||
|
||
await click('#test-input'); | ||
}); | ||
}); |