-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add peek-record helper - add peek-all helper - add query helper - add async-all helper - add async-hash helper
- Loading branch information
Showing
25 changed files
with
320 additions
and
78 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,11 @@ | ||
import Helper from '@ember/component/helper'; | ||
import { all, task } from 'ember-concurrency'; | ||
|
||
export default Helper.extend({ | ||
asyncAllTask: task(function * (tasks) { | ||
return yield all(tasks); | ||
}), | ||
compute([tasks/*, ...rest*/]/*, hash*/) { | ||
return this.asyncAllTask.perform(tasks); | ||
} | ||
}); |
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 Helper from '@ember/component/helper'; | ||
import { hash, task } from 'ember-concurrency'; | ||
|
||
export default Helper.extend({ | ||
asyncHashTask: task(function * (tasks) { | ||
return yield hash(tasks); | ||
}), | ||
compute([tasks/*, ...rest*/]/*, hash*/) { | ||
return this.asyncHashTask.perform(tasks); | ||
} | ||
}); |
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,13 @@ | ||
import Helper from '@ember/component/helper'; | ||
import { inject as service } from '@ember/service'; | ||
import { task } from 'ember-concurrency'; | ||
|
||
export default Helper.extend({ | ||
store: service(), | ||
peekAllTask: task(function * (modelType) { | ||
return yield this.store.peekAll(modelType); | ||
}), | ||
compute([modelType/*, ...rest*/]/*, hash*/) { | ||
return this.peekAllTask.perform(modelType); | ||
} | ||
}); |
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 { inject as service } from '@ember/service'; | ||
import { task } from 'ember-concurrency'; | ||
|
||
export default Helper.extend({ | ||
store: service(), | ||
peekRecordTask: task(function * (modelType, id) { | ||
return yield this.store.peekRecord(modelType, id); | ||
}), | ||
compute([modelType, id/*, ...rest*/]/*, hash*/) { | ||
if(!id) return null; | ||
return this.peekRecordTask.perform(modelType, id); | ||
} | ||
}); |
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,13 @@ | ||
import Helper from '@ember/component/helper'; | ||
import { inject as service } from '@ember/service'; | ||
import { task } from 'ember-concurrency'; | ||
|
||
export default Helper.extend({ | ||
store: service(), | ||
queryTask: task(function * (modelType, hash) { | ||
return yield this.store.query(modelType, hash); | ||
}), | ||
compute([modelType, hash/*, ...rest*/]/*, hash*/) { | ||
return this.queryTask.perform(modelType, hash); | ||
} | ||
}); |
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, asyncAll } from 'ember-needs-async/helpers/async-all'; |
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, asyncHash } from 'ember-needs-async/helpers/async-hash'; |
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, peekAll } from 'ember-needs-async/helpers/peek-all'; |
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, peekRecord } from 'ember-needs-async/helpers/peek-record'; |
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, query } from 'ember-needs-async/helpers/query'; |
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,20 +1,4 @@ | ||
import Controller from '@ember/controller'; | ||
import { task, timeout } from 'ember-concurrency'; | ||
|
||
export default Controller.extend({ | ||
askQuestion: task(function * () { | ||
yield timeout(1000); | ||
this.set('result', Math.random()); | ||
return this.result; | ||
}).drop(), | ||
|
||
result: null, | ||
|
||
taskInstance: null, | ||
|
||
actions: { | ||
onClick() { | ||
this.set('taskInstance', this.askQuestion.perform()); | ||
} | ||
} | ||
}); |
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,20 @@ | ||
import Controller from '@ember/controller'; | ||
import { task, timeout } from 'ember-concurrency'; | ||
|
||
export default Controller.extend({ | ||
askQuestion: task(function * () { | ||
yield timeout(1000); | ||
this.set('result', Math.random()); | ||
return this.result; | ||
}).drop(), | ||
|
||
result: null, | ||
|
||
taskInstance: null, | ||
|
||
actions: { | ||
onClick() { | ||
this.set('taskInstance', this.askQuestion.perform()); | ||
} | ||
} | ||
}); |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ const Router = EmberRouter.extend({ | |
}); | ||
|
||
Router.map(function() { | ||
this.route('sandbox'); | ||
}); | ||
|
||
export default Router; |
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,4 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default Route.extend({ | ||
}); |
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,57 +1,6 @@ | ||
<h2 id="title">Welcome to Ember</h2> | ||
{{!-- | ||
<button class={{if askQuestion.isIdle "button-primary"}} onclick={{perform askQuestion}}> | ||
--}} | ||
<button onclick={{action "onClick"}}> | ||
Button | ||
{{#needs-async needs=this.taskInstance as |states|}} | ||
{{#states.loading}}loading...{{/states.loading}} | ||
{{#states.loaded as |value|}}{{value}}{{/states.loaded}} | ||
{{#states.error as |error|}}{{error}}{{/states.error}} | ||
{{/needs-async}} | ||
</button> | ||
|
||
<div> | ||
<div> | ||
{{input value=userid}} | ||
</div> | ||
|
||
<div> | ||
<NeedsAsync @needs={{find-record "user" userid}} as |states|> | ||
{{#states.loading}}LOADING THE USER{{/states.loading}} | ||
|
||
{{#states.loaded as |user|}} | ||
{{user.lastName}}, {{user.firstName}} | ||
<div> | ||
<NeedsAsync @needs={{belongs-to user "company"}} as |states|> | ||
{{#states.loading}}LOADING COMPANY{{/states.loading}} | ||
{{#states.loaded as |company|}} | ||
<div> | ||
<div>{{company.name}} - {{company.motto}}</div> | ||
<div>{{company.street}} {{company.city}} {{company.state}} {{company.zip}}</div> | ||
</div> | ||
{{/states.loaded}} | ||
</NeedsAsync> | ||
<NeedsAsync @needs={{has-many user "friends"}} as |states|> | ||
{{#states.loading}}LOADING FRIENDS{{/states.loading}} | ||
{{#states.loaded as |friends|}} | ||
<div> | ||
{{#each friends as |friend|}} | ||
{{friend.fullName}}, | ||
{{/each}} | ||
</div> | ||
{{/states.loaded}} | ||
</NeedsAsync> | ||
</div> | ||
{{/states.loaded}} | ||
|
||
{{#states.error as |error|}} | ||
There was an error: {{error}} | ||
{{/states.error}} | ||
</NeedsAsync> | ||
</div> | ||
|
||
|
||
</div> | ||
<nav class="w-full h-8 bg-grey-light"> | ||
{{#link-to 'index'}}Main{{/link-to}} | ||
{{#link-to 'sandbox'}}Sandbox{{/link-to}} | ||
</nav> | ||
|
||
{{outlet}} |
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,64 @@ | ||
<h1>Main</h1> | ||
|
||
<button onclick={{action "onClick"}}> | ||
Button | ||
{{#needs-async needs=this.taskInstance as |states|}} | ||
{{#states.loading}}loading...{{/states.loading}} | ||
{{#states.loaded as |value|}}{{value}}{{/states.loaded}} | ||
{{#states.error as |error|}}{{error}}{{/states.error}} | ||
{{/needs-async}} | ||
</button> | ||
|
||
<div> | ||
<div> | ||
{{input value=userid}} | ||
</div> | ||
|
||
<div> | ||
<NeedsAsync @needs={{find-record "user" userid}} as |states|> | ||
{{#states.loading}}LOADING THE USER{{/states.loading}} | ||
|
||
{{#states.loaded as |user|}} | ||
<img src={{user.avatar}} alt="{{user.fullName}} profile picture"> | ||
{{user.lastName}}, {{user.firstName}} | ||
<div> | ||
<NeedsAsync @needs={{belongs-to user "company"}} as |states|> | ||
{{#states.loading}}LOADING COMPANY{{/states.loading}} | ||
{{#states.loaded as |company|}} | ||
<div> | ||
<div>{{company.name}} - {{company.motto}}</div> | ||
<div>{{company.street}} {{company.city}} {{company.state}} {{company.zip}}</div> | ||
</div> | ||
{{/states.loaded}} | ||
</NeedsAsync> | ||
<NeedsAsync @needs={{has-many user "friends"}} as |states|> | ||
{{#states.loading}}LOADING FRIENDS{{/states.loading}} | ||
{{#states.loaded as |friends|}} | ||
<div> | ||
{{#each friends as |friend|}} | ||
{{friend.fullName}}, | ||
{{/each}} | ||
</div> | ||
{{/states.loaded}} | ||
</NeedsAsync> | ||
</div> | ||
{{/states.loaded}} | ||
|
||
{{#states.error as |error|}} | ||
There was an error: {{error}} | ||
{{/states.error}} | ||
</NeedsAsync> | ||
<div> | ||
<NeedsAsync @needs={{peek-all "user"}} as |States|> | ||
<#States.loaded as |users|> | ||
Loaded users: {{users.length}} | ||
</States.loaded> | ||
</NeedsAsync> | ||
</div> | ||
</div> | ||
|
||
|
||
</div> | ||
|
||
|
||
{{outlet}} |
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,51 @@ | ||
<h1>Sandbox</h1> | ||
|
||
<NeedsAsync @needs={{async-all (array | ||
(find-record "user" "1") | ||
(find-record "user" "2") | ||
(find-record "user" "3") | ||
)}} as |States|> | ||
<#States.loading> | ||
Loading... | ||
</States.loading> | ||
|
||
<#States.loaded as |users|> | ||
{{#each users as |user|}} | ||
{{user.fullName}}, | ||
{{/each}} | ||
</States.loaded> | ||
</NeedsAsync> | ||
|
||
|
||
<NeedsAsync @needs={{async-hash (hash | ||
carol=(find-record "user" "1") | ||
carl=(find-record "user" "2") | ||
cambert=(find-record "user" "3") | ||
)}} as |States|> | ||
<#States.loading> | ||
Loading... | ||
</States.loading> | ||
|
||
<#States.loaded as |users|> | ||
{{#each-in users as |name user|}} | ||
{{name}}:{{user.fullName}}, | ||
{{/each-in}} | ||
</States.loaded> | ||
</NeedsAsync> | ||
|
||
<div> | ||
QUERY: | ||
<NeedsAsync @needs={{query "user" (hash page="2" size="5")}} as |States|> | ||
<#States.loading> | ||
Loading... | ||
</States.loading> | ||
|
||
<#States.loaded as |users|> | ||
{{#each users as |user|}} | ||
{{user.fullName}}, | ||
{{/each}} | ||
</States.loaded> | ||
</NeedsAsync> | ||
</div> | ||
|
||
{{outlet}} |
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,17 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
module('Integration | Helper | async-all', function(hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
// Replace this with your real tests. | ||
test('it renders', async function(assert) { | ||
this.set('inputValue', '1234'); | ||
|
||
await render(hbs`{{async-all inputValue}}`); | ||
|
||
assert.equal(this.element.textContent.trim(), '1234'); | ||
}); | ||
}); |
Oops, something went wrong.