Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions app/components/post-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@ import { task, all } from "ember-concurrency";
export default Component.extend({
store: service(),

init() {
this._super(...arguments);
this.set("forkedStore", this.store.fork());
},

createPostsTask: task(function*() {
let posts = [1, 2, 3, 4].map(i =>
this.store.createRecord("post", {
title: `Title ${i}`,
body: `body ${i}`
})
let posts = yield all(
[1, 2, 3, 4].map(i =>
this.forkedStore.addRecord({
type: "post",
title: `Title ${i}`,
body: `body ${i}`
})
)
);

yield all(posts.map(post => post.save()));
yield this.store.merge(this.forkedStore);

this.set("forkedStore", this.store.fork());
this.set("posts", posts);
}).drop()
});
9 changes: 9 additions & 0 deletions app/data-sources/remote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import JSONAPISource from "@orbit/jsonapi";

export default {
create(injections = {}) {
injections.name = "remote";

return new JSONAPISource(injections);
}
};
7 changes: 7 additions & 0 deletions app/data-strategies/event-logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { EventLoggingStrategy } from "@orbit/coordinator";

export default {
create() {
return new EventLoggingStrategy();
}
};
17 changes: 17 additions & 0 deletions app/data-strategies/remote-request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { RequestStrategy } from "@orbit/coordinator";

export default {
create() {
return new RequestStrategy({
name: "remote-request",

source: "store",
on: "beforeQuery",

target: "remote",
action: "pull",

blocking: true
});
}
};
14 changes: 14 additions & 0 deletions app/data-strategies/remote-sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { SyncStrategy } from "@orbit/coordinator";

export default {
create() {
return new SyncStrategy({
name: "remote-sync",

source: "remote",
target: "store",

blocking: false
});
}
};
17 changes: 17 additions & 0 deletions app/data-strategies/remote-update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { RequestStrategy } from "@orbit/coordinator";

export default {
create() {
return new RequestStrategy({
name: "remote-update",

source: "store",
on: "beforeUpdate",

target: "remote",
action: "push",

blocking: true
});
}
};
4 changes: 1 addition & 3 deletions app/models/post.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import DS from "ember-data";

const { Model, attr } = DS;
import { Model, attr } from "ember-orbit";

export default Model.extend({
title: attr("string"),
Expand Down
9 changes: 8 additions & 1 deletion app/routes/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import Route from "@ember/routing/route";
import { inject as service } from "@ember/service";

export default Route.extend({});
export default Route.extend({
dataCoordinator: service(),

beforeModel() {
this.dataCoordinator.activate();
}
});
12 changes: 9 additions & 3 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
'use strict';
"use strict";

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const EmberApp = require("ember-cli/lib/broccoli/ember-app");

module.exports = function(defaults) {
let app = new EmberApp(defaults, {
// Add options here
orbit: {
packages: [
"@orbit/jsonapi",
"@orbit/local-storage",
"@orbit/local-storage-bucket"
]
}
});

// Use `app.import` to add additional libraries to the generated
Expand Down
8 changes: 7 additions & 1 deletion mirage/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export default function() {
this.resource("post");
this.pretender.prepareHeaders = function(headers) {
headers["Content-Type"] = "application/vnd.api+json";
return headers;
};
this.logging = true;

this.resource("posts");
}
4 changes: 4 additions & 0 deletions mirage/models/posts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Model } from 'ember-cli-mirage';

export default Model.extend({
});
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"ember-cli-template-lint": "^1.0.0-beta.1",
"ember-cli-uglify": "^2.1.0",
"ember-concurrency": "^0.8.26",
"ember-data": "~3.4.0",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.1.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-orbit": "^0.15.10",
"ember-resolver": "^5.0.1",
"ember-source": "~3.4.0",
"ember-welcome-page": "^3.2.0",
Expand All @@ -49,5 +49,11 @@
},
"engines": {
"node": "6.* || 8.* || >= 10.*"
},
"dependencies": {
"@orbit/jsonapi": "^0.15.25",
"@orbit/local-storage": "^0.15.23",
"@orbit/local-storage-bucket": "^0.15.23",
"@orbit/store": "^0.15.25"
}
}
13 changes: 0 additions & 13 deletions tests/unit/models/post-test.js

This file was deleted.

Loading