ember-data-model-fragments
Advanced tools
Comparing version
# Changelog | ||
### v0.4.3 (October 14, 2015) | ||
* Updated API and added deprecation warnings to all outdated APIs | ||
* Fixed issue with initializer arguments in Ember 2.1 (@jakesjews) | ||
### v0.4.2 (October 11, 2015) | ||
@@ -14,4 +19,4 @@ | ||
* Added warning about changing default value for array fragment properties | ||
* Added support for copying nested fragments (louy) | ||
* Fixed broken fragment copying (jakesjews) | ||
* Added support for copying nested fragments (@louy) | ||
* Fixed broken fragment copying (@jakesjews) | ||
@@ -25,4 +30,4 @@ ### v0.4.0 (August 14, 2015) | ||
* Removed deprecations in test suite | ||
* Removed computed property deprecations (jakesjews) | ||
* Added fragment transform module for unit testing ember-cli apps (rwjblue) | ||
* Removed computed property deprecations (@jakesjews) | ||
* Added fragment transform module for unit testing ember-cli apps (@rwjblue) | ||
@@ -45,3 +50,3 @@ ### v0.3.2 (April 20, 2015) | ||
* Fixed infinite loops when reloading observed fragments (igort) | ||
* Fixed infinite loops when reloading observed fragments (@igort) | ||
@@ -66,3 +71,3 @@ ### v0.2.7 (January 16, 2015) | ||
* Updated to support Ember Data v1.0.0-beta.14 (igort) | ||
* Updated to support Ember Data v1.0.0-beta.14 (@igort) | ||
@@ -76,3 +81,3 @@ ### v0.2.3 (January 5, 2015) | ||
* Added support for polymorphic fragments (marcus-nl) | ||
* Added support for polymorphic fragments (@marcus-nl) | ||
@@ -79,0 +84,0 @@ ### v0.2.1 (October 2, 2014) |
@@ -1,1 +0,1 @@ | ||
export default DS.ArrayTransform; | ||
export default MF.ArrayTransform; |
@@ -1,1 +0,1 @@ | ||
export default DS.FragmentArrayTransform; | ||
export default MF.FragmentArrayTransform; |
@@ -1,1 +0,1 @@ | ||
export default DS.FragmentTransform; | ||
export default MF.FragmentTransform; |
import DS from 'ember-data'; | ||
import MF from 'model-fragments'; | ||
export default DS.ModelFragment.extend({ | ||
export default MF.Fragment.extend({ | ||
<%= attrs %> | ||
}); | ||
}); |
@@ -13,3 +13,11 @@ 'use strict'; | ||
}); | ||
app.import('vendor/ember-data-model-fragments/shim.js', { | ||
exports: { | ||
'model-fragments': [ | ||
'default' | ||
] | ||
} | ||
}); | ||
} | ||
}; | ||
}; |
{ | ||
"name": "ember-data-model-fragments", | ||
"description": "Ember Data addon to support nested JSON documents", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
@@ -1,2 +0,2 @@ | ||
# Ember Data: Model Fragments | ||
# Ember Data Model Fragments | ||
@@ -9,9 +9,8 @@ [](https://travis-ci.org/lytics/ember-data.model-fragments) | ||
:warning: The API has changed significantly in preparation for v1.0. Deprecations have been added to all updated APIs with instructions on how to upgrade. | ||
:warning: Ember Data v1.0.0-beta.12 introduced a bug that makes it incompatible with any version of this project. | ||
## Compatibility | ||
:warning: 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. | ||
This project makes extensive use of private Ember Data APIs and is therefore sensitive to minor changes in new Ember Data releases, regardless of semver guarantees. Every effort is made to maintain compatibility with the latest version, but updates always take time. See the [contributing](#contributing) section if you'd like to help out :shipit: | ||
:warning: 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. | ||
Use the following table to decide which version of this project to use with your app: | ||
@@ -24,4 +23,10 @@ | ||
| >= v1.0.0-beta.15 <= v1.0.0-beta.18 | v0.3.3 | | ||
| >= v1.13.x | >= v0.4.0 | | ||
| >= v1.13.x | >= v0.4.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. | ||
## Installation | ||
@@ -41,3 +46,3 @@ | ||
Which will create the module `app/models/foo.js` which exports a `DS.ModelFragment` class with the given attributes. | ||
Which will create the module `app/models/foo.js` which exports a `MF.Fragment` class with the given attributes. | ||
@@ -48,8 +53,8 @@ ## Example | ||
App.Person = DS.Model.extend({ | ||
name : DS.hasOneFragment('name'), | ||
addresses : DS.hasManyFragments('address'), | ||
titles : DS.hasManyFragments() | ||
name : MF.fragment('name'), | ||
addresses : MF.fragmentArray('address'), | ||
titles : MF.array() | ||
}); | ||
App.Name = DS.ModelFragment.extend({ | ||
App.Name = MF.Fragment.extend({ | ||
first : DS.attr('string'), | ||
@@ -59,3 +64,3 @@ last : DS.attr('string') | ||
App.Address = DS.ModelFragment.extend({ | ||
App.Address = MF.Fragment.extend({ | ||
street : DS.attr('string'), | ||
@@ -165,13 +170,13 @@ city : DS.attr('string'), | ||
Ember Data attributes [support a `defaultValue` config option](http://emberjs.com/api/data/classes/DS.html#method_attr) that provides a default value when a model is created through `store#createRecord()`. Similarly, `DS.hasOneFragment` and `DS.hasManyFragments` properties support a `defaultValue` option: | ||
Ember Data attributes [support a `defaultValue` config option](http://emberjs.com/api/data/classes/DS.html#method_attr) that provides a default value when a model is created through `store#createRecord()`. Similarly, `MF.fragment` and `MF.fragmentArray` properties support a `defaultValue` option: | ||
```javascript | ||
App.Person = DS.Model.extend({ | ||
name : DS.hasOneFragment('name', { defaultValue: { first: 'Faceless', last: 'Man' } }), | ||
addresses : DS.hasManyFragments('address', { defaultValue: [] }), | ||
titles : DS.hasManyFragments(null, { defaultValue: [] }) | ||
name : MF.fragment('name', { defaultValue: { first: 'Faceless', last: 'Man' } }), | ||
addresses : MF.fragmentArray('address', { defaultValue: [] }), | ||
titles : MF.array('string', { defaultValue: [] }) | ||
}); | ||
``` | ||
Since JavaScript objects and arrays are passed by reference, the value of `defaultValue` is copied using `Ember.copy` in order to prevent all instances sharing the same value. If a `defaultValue` option is not specified, both `DS.hasOneFragment` and `DS.hasManyFragments` properties will default to `null`. Note that this may cause confusion when creating a record with a `DS.hasManyFragments` property: | ||
Since JavaScript objects and arrays are passed by reference, the value of `defaultValue` is copied using `Ember.copy` in order to prevent all instances sharing the same value. If a `defaultValue` option is not specified, both `MF.fragment` and `MF.fragmentArray` properties will default to `null`. Note that this may cause confusion when creating a record with a `MF.fragmentArray` property: | ||
@@ -192,3 +197,3 @@ ```javascript | ||
App.Person = DS.Model.extend({ | ||
name: DS.hasOneFragment('name', { | ||
name: MF.fragment('name', { | ||
defaultValue: function() { | ||
@@ -208,3 +213,3 @@ return { | ||
```javascript | ||
App.Name = DS.ModelFragment.extend({ | ||
App.Name = MF.Fragment.extend({ | ||
given : DS.attr('string'), | ||
@@ -260,11 +265,11 @@ family : DS.attr('string') | ||
name : DS.attr('string'), | ||
orders : DS.hasManyFragments('order') | ||
orders : MF.fragmentArray('order') | ||
}); | ||
App.Order = DS.ModelFragment.extend({ | ||
App.Order = MF.Fragment.extend({ | ||
amount : DS.attr('string'), | ||
products : DS.hasManyFragments('product') | ||
products : MF.fragmentArray('product') | ||
}); | ||
App.Product = DS.ModelFragment.extend({ | ||
App.Product = MF.Fragment.extend({ | ||
name : DS.attr('string'), | ||
@@ -333,3 +338,3 @@ sku : DS.attr('string'), | ||
Ember Data: Model Fragments has support for *reading* polymorphic fragments. To use this feature, pass an options object to `hasOneFragment` or `hasManyFragments` | ||
Ember Data: Model Fragments has support for *reading* polymorphic fragments. To use this feature, pass an options object to `MF.fragment` or `MF.fragmentArray` | ||
with `polymorphic` set to true. In addition the `typeKey` can be set, which defaults to `'type'`. | ||
@@ -346,6 +351,6 @@ | ||
city: DS.attr("string"), | ||
animals: DS.hasManyFragments("animal", { polymorphic: true, typeKey: '$type' }), | ||
animals: MF.fragmentArray("animal", { polymorphic: true, typeKey: '$type' }), | ||
}); | ||
App.Animal = DS.ModelFragment.extend({ | ||
App.Animal = MF.Fragment.extend({ | ||
name: DS.attr("string"), | ||
@@ -352,0 +357,0 @@ }); |
23621
3.82%14
7.69%75
29.31%456
1.11%