{{post.title}}
+{{post.body}}
+diff --git a/app/components/post-creator.js b/app/components/post-creator.js index c995991..f85f0d8 100644 --- a/app/components/post-creator.js +++ b/app/components/post-creator.js @@ -1,20 +1,33 @@ import Component from "@ember/component"; import { inject as service } from "@ember/service"; -import { task, all } from "ember-concurrency"; +import { task } from "ember-concurrency"; export default Component.extend({ store: service(), createPostsTask: task(function*() { - let posts = [1, 2, 3, 4].map(i => - this.store.createRecord("post", { - title: `Title ${i}`, - body: `body ${i}` - }) - ); + let p1 = this.store.createRecord("post", { + title: `Title 1`, + body: `body 1` + }); + yield p1.save(); - yield all(posts.map(post => post.save())); + let p2 = this.store.createRecord("post", { + title: `Title 2`, + body: `body 2` + }); + yield p2.save(); - this.set("posts", posts); + let p3 = this.store.createRecord("post", { + title: `Title 3`, + body: `body 3` + }); + yield p3.save(); + + let p4 = this.store.createRecord("post", { + title: `Title 4`, + body: `body 4` + }); + yield p4.save(); }).drop() }); diff --git a/app/routes/application.js b/app/routes/application.js index f7f5da2..874d72b 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -1,3 +1,7 @@ import Route from "@ember/routing/route"; -export default Route.extend({}); +export default Route.extend({ + model() { + return this.store.findAll("post"); + } +}); diff --git a/app/templates/application.hbs b/app/templates/application.hbs index f8978d0..3bdbbe7 100644 --- a/app/templates/application.hbs +++ b/app/templates/application.hbs @@ -1 +1,10 @@ {{post-creator}} + +{{#each this.model as |post|}} +
{{post.body}}
+no posts
+{{/each}} diff --git a/app/templates/components/post-creator.hbs b/app/templates/components/post-creator.hbs index 1af3a85..581b21b 100644 --- a/app/templates/components/post-creator.hbs +++ b/app/templates/components/post-creator.hbs @@ -1,11 +1,3 @@ {{#if this.createPostsTask.isRunning}}creating...{{/if}} -{{#each this.posts as |post|}} -{{post.body}}
-no posts
-{{/each}}