Skip to content

Commit

Permalink
Adding support for ember-data 2.11. (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
workmanw authored Jan 19, 2017
1 parent 9f711f6 commit a856c24
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 68 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ cache:
- $HOME/.cache # includes bowers cache

env:
- EMBER_TRY_SCENARIO=ember-lts-2.4
- EMBER_TRY_SCENARIO=ember-lts-2.8
- EMBER_TRY_SCENARIO=ember-2-11
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ Use the following table to decide which version of this project to use with your
| >= v1.13.x < v2.0.0 | v1.13.x |
| >= v2.0.x < v2.1.0 | v2.0.x |
| >= v2.1.x < v2.3.x | v2.1.x |
| >= v2.3.x | v2.3.x |
| >= v2.3.x < v2.11.x | v2.3.x |
| >= v2.11.x | v2.11.x |

#### Notes

- Ember Data v1.0.0-beta.12 introduced a bug that makes it incompatible with any version of this project.
- Ember Data v1.0.0-beta.15 introduced a breaking change to the serializer API with [Snapshots](https://github.com/emberjs/data/pull/2623). Since this affected fragment serialization as well, support for it was added in v0.3.0. See the [serializing](#serializing) section below for more information.
- Ember Data v1.0.0-beta.19 refactored a large number of internal APIs this project relied on and is not officially supported. Compatibility was added in v0.4.0 and targeted at Ember Data v1.13.x.
- Ember Data 2.3 converted to a full Ember CLI addon. Removing the global `DS` namespace and switching to an import module strategy. More: [Ember Data 2.3 Released](http://emberjs.com/blog/2016/01/12/ember-data-2-3-released.html). Following ember-data's lead, the `MF` namespace was also removed. Import modules directly.
- Ember Data 2.11 changed the implementation of their `ContainerInstanceCache`. We had to follow suite with our patches so that we could continue offering fragments their own default serializer. See [#224](https://github.com/lytics/ember-data-model-fragments/issues/224).

## Installation

Expand Down
61 changes: 26 additions & 35 deletions addon/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Ember from 'ember';
import Store from 'ember-data/store';
import Model from 'ember-data/model';
import InternalModel from 'ember-data/-private/system/model/internal-model';
import ContainerInstanceCache from 'ember-data/-private/system/store/container-instance-cache';
import JSONSerializer from 'ember-data/serializers/json';
import FragmentRootState from './states';
import {
Expand Down Expand Up @@ -80,41 +81,6 @@ Store.reopen({
isFragment(modelName) {
var type = this.modelFor(modelName);
return Fragment.detect(type);
},

/**
Changes serializer fallbacks for fragments to use `serializer:-fragment`
if registered, then uses the default serializer.
@method serializerFor
@private
@param {String} modelName the record to serialize
@return {DS.Serializer}
*/
serializerFor: function(modelOrClass) {
var modelName;

if (typeof modelOrClass === 'string') {
modelName = modelOrClass;
} else {
modelName = modelOrClass.modelName;
}

// Don't fail on non-model lookups ('application', '-default', etc.)
var type = this.modelFactoryFor(modelName);

// For fragments, don't use the application serializer or adapter default
// as a fallbacks
if (type && Fragment.detect(type)) {
var fallbacks = [
'-fragment',
'-default'
];

return this.lookupSerializer(modelName, fallbacks);
}

return this._super(modelOrClass);
}
});

Expand Down Expand Up @@ -342,4 +308,29 @@ function getFragmentTransform(owner, store, attributeType) {
return owner.lookup(containerKey);
}

/*
Patch ember-data's ContainerInstanceCache. Changes fallbacks for fragments
to use `serializer:-fragment` if registered, then uses the default serializer.
Previously this was implemented by overriding the `serializerFor` on the store,
however an ember-data improved their implementation, so we followed suite.
See: https://github.com/lytics/ember-data-model-fragments/issues/224
*/
(function patchContainerInstanceCache(instanceCache) {
var ContainerInstanceCachePrototype = ContainerInstanceCache.prototype;
var _super = ContainerInstanceCachePrototype._fallbacksFor;
ContainerInstanceCachePrototype._fallbacksFor = function _modelFragmentsPatchedFallbacksFor(namespace, preferredKey) {
if (namespace === 'serializer') {
var model = this._store.modelFactoryFor(preferredKey);
if (model && Fragment.detect(model)) {
return [
'-fragment',
'-default'
];
}
}

return _super.apply(this, [namespace, preferredKey]);
};
})();

export { Store, Model, JSONSerializer };
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ember-data-model-fragments",
"devDependencies": {
"ember": "~2.10.0",
"ember": "~2.11.0-beta.4",
"ember-cli-shims": "0.1.3",
"pretender": "^1.0.0"
}
Expand Down
35 changes: 8 additions & 27 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*jshint node:true*/
module.exports = {
module.exports = function() {
return {
scenarios: [
{
name: 'default',
Expand All @@ -12,41 +13,21 @@ module.exports = {
},

{
name: 'ember-lts-2.4',
name: 'ember-2-11',
bower: {
devDependencies: {
'ember': 'components/ember#lts-2-4'
'ember': '~2.11.0-beta.4',
},
resolutions: {
'ember': 'lts-2-4'
'ember': '~2.11.0-beta.4',
}
},
npm: {
devDependencies: {
'ember-data': '2.4.3'
'ember-data': '~2.11.0'
},
resolutions: {
'ember-data': '2.4.3'
}
}
},

{
name: 'ember-lts-2.8',
bower: {
dependencies: {
'ember': 'components/ember#lts-2-8'
},
resolutions: {
'ember': 'lts-2-8'
}
},
npm: {
devDependencies: {
'ember-data': '2.8.1'
},
resolutions: {
'ember-data': '2.8.1'
'ember-data': '~2.11.0'
}
}
},
Expand Down Expand Up @@ -91,5 +72,5 @@ module.exports = {
}
}
}
]
]};
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ember-data-model-fragments",
"description": "Ember Data addon to support nested JSON documents",
"version": "2.3.3",
"version": "2.11.0",
"repository": {
"type": "git",
"url": "https://github.com/lytics/ember-data-model-fragments.git"
Expand Down Expand Up @@ -38,7 +38,7 @@
"ember-cli-release": "^1.0.0-beta.2",
"ember-cli-test-loader": "^1.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "^2.10.0",
"ember-data": "~2.11.0",
"ember-dev": "emberjs/ember-dev",
"ember-disable-prototype-extensions": "^1.1.0",
"ember-load-initializers": "^0.5.1",
Expand Down

0 comments on commit a856c24

Please sign in to comment.