Skip to content

Commit

Permalink
Merge pull request #30 from embermap/update
Browse files Browse the repository at this point in the history
Update addon to Ember 3.0/ED 3.0
  • Loading branch information
ryanto authored Mar 1, 2018
2 parents 222d165 + f3fd921 commit ce70744
Show file tree
Hide file tree
Showing 31 changed files with 692 additions and 505 deletions.
39 changes: 37 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,45 @@ module.exports = {
ecmaVersion: 2017,
sourceType: 'module'
},
extends: 'eslint:recommended',
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
env: {
browser: true
},
rules: {
}
},
overrides: [
// node files
{
files: [
'index.js',
'testem.js',
'ember-cli-build.js',
'config/**/*.js',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'app/**',
'addon/**',
'tests/dummy/app/**'
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
},
env: {
browser: false,
node: true
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
}
]
};
7 changes: 6 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
.bowerrc
.editorconfig
.ember-cli
.gitignore
.eslintrc.js
.gitignore
.watchmanconfig
.travis.yml
bower.json
ember-cli-build.js
testem.js

# ember-try
.node_modules.ember-try/
bower.json.ember-try
package.json.ember-try
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ install:

before_script:
- ember version
- yarn list
- yarn list | grep ember-source
- yarn list | grep ember-data

notifications:
email: false
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2017
Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
9 changes: 5 additions & 4 deletions addon/components/assert-must-preload/component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from 'ember';
import { assert } from '@ember/debug';
import Component from '@ember/component';

/**
_This component relies on JSON:API, and assumes that your server supports JSON:API includes._
Expand All @@ -24,7 +25,7 @@ import Ember from 'ember';
@class AssertMustPreload
@public
*/
export default Ember.Component.extend({
export default Component.extend({
tagName: '',

didReceiveAttrs() {
Expand All @@ -33,12 +34,12 @@ export default Ember.Component.extend({
let parentName = parentComponent ? parentComponent._debugContainerKey : 'template';
let includesString = includes.join(',');

Ember.assert(
assert(
`You passed a ${model.constructor.modelName} model into an {{assert-must-preload}}, but that model is not using the Loadable mixin. [ember-data-storefront]`,
model.hasLoaded
);

Ember.assert(
assert(
`You tried to render a ${parentName} that accesses relationships off of a ${model.constructor.modelName}, but that model didn't have all of its required relationships preloaded ('${includesString}'). Please make sure to preload the association. [ember-data-storefront]`,
model.hasLoaded(includesString)
);
Expand Down
8 changes: 3 additions & 5 deletions addon/mixins/loadable-model.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Ember from 'ember';
import Mixin from '@ember/object/mixin';

/**
_This mixin relies on JSON:API, and assumes that your server supports JSON:API includes._
Expand Down Expand Up @@ -28,11 +28,9 @@ import Ember from 'ember';
@class LoadableModel
@public
*/
export default Ember.Mixin.create({
export default Mixin.create({

store: Ember.inject.service(),

/**
/**
`load` gives you an explicit way to asynchronously load related data.
```js
Expand Down
4 changes: 2 additions & 2 deletions addon/mixins/loadable-store.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Ember from 'ember';
import Mixin from '@ember/object/mixin';
import { resolve } from 'rsvp';
import Coordinator from 'ember-data-storefront/-private/coordinator';

Expand All @@ -10,7 +10,7 @@ import Coordinator from 'ember-data-storefront/-private/coordinator';
@class LoadableStore
@public
*/
export default Ember.Mixin.create({
export default Mixin.create({

init() {
this._super(...arguments);
Expand Down
4 changes: 2 additions & 2 deletions addon/mixins/loadable.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Ember from 'ember';
import Mixin from '@ember/object/mixin';
import { deprecate } from '@ember/application/deprecations';
import { on } from '@ember/object/evented';
import LoadableModel from './loadable-model';

export default Ember.Mixin.create(LoadableModel, {
export default Mixin.create(LoadableModel, {

showDeprecations: on('init', function() {
deprecate(
Expand Down
18 changes: 10 additions & 8 deletions addon/mixins/snapshottable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Ember from 'ember';
import { assert } from '@ember/debug';
import { isArray } from '@ember/array';
import Mixin from '@ember/object/mixin';

export default Ember.Mixin.create({
export default Mixin.create({

/*
Graph for a post looks like
Expand Down Expand Up @@ -36,7 +38,7 @@ export default Ember.Mixin.create({
Object.keys(graph).forEach(key => {
let node = graph[key];
let relationship = this.get(key);
if (Ember.isArray(relationship)) {
if (isArray(relationship)) {
snapshot.relationships[key] = relationship.map(model => ({ model, relationships: {} }));
} else {
snapshot.relationships[key] = { model: relationship, relationships: {} };
Expand All @@ -47,11 +49,11 @@ export default Ember.Mixin.create({
Object.keys(node).forEach(subkey => {
let namedRelationshipMeta = snapshot.relationships[key];
if (namedRelationshipMeta) {
if (Ember.isArray(namedRelationshipMeta)) {
if (isArray(namedRelationshipMeta)) {
namedRelationshipMeta.forEach(relationshipSnapshot => {
let nestedRelationship = relationshipSnapshot.model.get(subkey);

if (Ember.isArray(nestedRelationship)) {
if (isArray(nestedRelationship)) {
relationshipSnapshot.relationships[subkey] = nestedRelationship.map(model => ({ model, relationships: {} }));
} else {
relationshipSnapshot.relationships[subkey] = { model: nestedRelationship, relationships: {} };
Expand Down Expand Up @@ -98,13 +100,13 @@ export default Ember.Mixin.create({

Object.keys(snapshot.relationships).forEach(key => {
let relationshipSnapshot = snapshot.relationships[key];
if (Ember.isArray(relationshipSnapshot)) {
if (isArray(relationshipSnapshot)) {
this.set(key, relationshipSnapshot.map(meta => meta.model));
relationshipSnapshot.forEach(rSnapshot => {
let model = rSnapshot.model;
model.rollbackAttributes();
if (Object.keys(rSnapshot.relationships).length) {
Ember.assert(`You're trying to restore a snapshot on a ${model._debugContainerKey} but that model isn't snapshottable. Be sure to include the Snapshottable mixin.`, model.restoreSnapshot !== undefined);
assert(`You're trying to restore a snapshot on a ${model._debugContainerKey} but that model isn't snapshottable. Be sure to include the Snapshottable mixin.`, model.restoreSnapshot !== undefined);
model.restoreSnapshot(rSnapshot);
}
});
Expand All @@ -118,7 +120,7 @@ export default Ember.Mixin.create({
}

if (Object.keys(relationshipSnapshot.relationships).length) {
Ember.assert(`You're trying to restore a snapshot on a ${model._debugContainerKey} but that model isn't snapshottable. Be sure to include the Snapshottable mixin.`, model.restoreSnapshot !== undefined);
assert(`You're trying to restore a snapshot on a ${model._debugContainerKey} but that model isn't snapshottable. Be sure to include the Snapshottable mixin.`, model.restoreSnapshot !== undefined);
model.restoreSnapshot(relationshipSnapshot);
}
}
Expand Down
5 changes: 2 additions & 3 deletions addon/services/storefront.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Ember from 'ember';
import Service from '@ember/service';
import Service, { inject as service } from '@ember/service';
import { deprecate } from '@ember/application/deprecations';

// do not delete this service! it's being used to communicte cached payloads
// between the client and the browser
export default Service.extend({
store: Ember.inject.service(),
store: service(),

fastbootDataRequests: null,

Expand Down
Loading

0 comments on commit ce70744

Please sign in to comment.