@ember-data/model 4.1.0-beta.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,17 +24,17 @@ import { computedMacroWithOptionalParams } from './util';
24
24
 
25
25
  ```app/models/post.js
26
26
  import Model, { hasMany } from '@ember-data/model';
27
-
27
+
28
28
  export default class PostModel extends Model {
29
- @hasMany('comment') comments;
29
+ @hasMany('comment') comments;
30
30
  }
31
31
  ```
32
32
 
33
33
  ```app/models/comment.js
34
34
  import Model, { belongsTo } from '@ember-data/model';
35
-
35
+
36
36
  export default class CommentModel extends Model {
37
- @belongsTo('post') post;
37
+ @belongsTo('post') post;
38
38
  }
39
39
  ```
40
40
 
@@ -54,7 +54,7 @@ import { computedMacroWithOptionalParams } from './util';
54
54
  import Model, { hasMany } from '@ember-data/model';
55
55
 
56
56
  export default class TagModel extends Model {
57
- @hasMany('post') posts;
57
+ @hasMany('post') posts;
58
58
  }
59
59
  ```
60
60
 
@@ -16,6 +16,7 @@ import { CUSTOM_MODEL_CLASS, RECORD_DATA_ERRORS, REQUEST_SERVICE } from '@ember-
16
16
  import { HAS_DEBUG_PACKAGE } from '@ember-data/private-build-infra';
17
17
  import {
18
18
  DEPRECATE_EVENTED_API_USAGE,
19
+ DEPRECATE_MODEL_TOJSON,
19
20
  DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS,
20
21
  } from '@ember-data/private-build-infra/deprecations';
21
22
  import {
@@ -77,7 +78,7 @@ function findPossibleInverses(type, inverseType, name, relationshipsSoFar) {
77
78
 
78
79
  /*
79
80
  * This decorator allows us to lazily compute
80
- * an expensive getter on first-access and thereafter
81
+ * an expensive getter on first-access and therafter
81
82
  * never recompute it.
82
83
  */
83
84
  function computeOnce(target, key, desc) {
@@ -118,8 +119,10 @@ function computeOnce(target, key, desc) {
118
119
  @uses DeprecatedEvented
119
120
  */
120
121
  class Model extends EmberObject {
121
- init(...args) {
122
- super.init(...args);
122
+ init(options = {}) {
123
+ const createProps = options._createProps;
124
+ delete options._createProps;
125
+ super.init(options);
123
126
 
124
127
  if (DEBUG) {
125
128
  if (!this._internalModel) {
@@ -132,6 +135,7 @@ class Model extends EmberObject {
132
135
  if (CUSTOM_MODEL_CLASS) {
133
136
  this.___recordState = new RecordState(this);
134
137
  }
138
+ this.setProperties(createProps);
135
139
  }
136
140
 
137
141
  /**
@@ -1866,7 +1870,7 @@ class Model extends EmberObject {
1866
1870
 
1867
1871
  ```javascript
1868
1872
  import { get } from '@ember/object';
1869
- import Person from 'app/models/person'
1873
+ import Blog from 'app/models/blog'
1870
1874
 
1871
1875
  let attributes = Person.attributes
1872
1876
 
@@ -2075,6 +2079,7 @@ class Model extends EmberObject {
2075
2079
  // the values initialized during create to `setUnknownProperty`
2076
2080
  Model.prototype._internalModel = null;
2077
2081
  Model.prototype.store = null;
2082
+ Model.prototype._createProps = null;
2078
2083
 
2079
2084
  if (HAS_DEBUG_PACKAGE) {
2080
2085
  /**
@@ -2172,6 +2177,47 @@ if (DEPRECATE_EVENTED_API_USAGE) {
2172
2177
  });
2173
2178
  }
2174
2179
 
2180
+ if (DEPRECATE_MODEL_TOJSON) {
2181
+ /**
2182
+ Use [JSONSerializer](JSONSerializer.html) to
2183
+ get the JSON representation of a record.
2184
+
2185
+ `toJSON` takes an optional hash as a parameter, currently
2186
+ supported options are:
2187
+
2188
+ - `includeId`: `true` if the record's ID should be included in the
2189
+ JSON representation.
2190
+
2191
+ @method toJSON
2192
+ @public
2193
+ @param {Object} options
2194
+ @return {Object} A JSON representation of the object.
2195
+ */
2196
+ Model.reopen({
2197
+ toJSON(options) {
2198
+ // container is for lazy transform lookups
2199
+ deprecate(
2200
+ `Called the built-in \`toJSON\` on the record "${this.constructor.modelName}:${this.id}". The built-in \`toJSON\` method on instances of classes extending \`Model\` is deprecated. For more information see the link below.`,
2201
+ false,
2202
+ {
2203
+ id: 'ember-data:model.toJSON',
2204
+ until: '4.0',
2205
+ url: 'https://deprecations.emberjs.com/ember-data/v3.x#toc_record-toJSON',
2206
+ for: '@ember-data/model',
2207
+ since: {
2208
+ available: '3.15',
2209
+ enabled: '3.15',
2210
+ },
2211
+ }
2212
+ );
2213
+ let serializer = this._internalModel.store.serializerFor('-default');
2214
+ let snapshot = this._internalModel.createSnapshot();
2215
+
2216
+ return serializer.serialize(snapshot, options);
2217
+ },
2218
+ });
2219
+ }
2220
+
2175
2221
  if (DEBUG) {
2176
2222
  let lookupDescriptor = function lookupDescriptor(obj, keyName) {
2177
2223
  let current = obj;
@@ -1,3 +1,4 @@
1
+ import ArrayMixin from '@ember/array';
1
2
  import { assert } from '@ember/debug';
2
3
  import { dependentKeyCompat } from '@ember/object/compat';
3
4
  import { tracked } from '@glimmer/tracking';
@@ -16,7 +17,7 @@ import { DEPRECATE_EVENTED_API_USAGE } from '@ember-data/private-build-infra/dep
16
17
 
17
18
  A PromiseManyArray is an array-like proxy that also proxies certain method calls
18
19
  to the underlying ManyArray in addition to being "promisified".
19
-
20
+
20
21
  Right now we proxy:
21
22
 
22
23
  * `reload()`
@@ -41,6 +42,14 @@ export default class PromiseManyArray {
41
42
  this._update(promise, content);
42
43
  this.isDestroyed = false;
43
44
  this.isDestroying = false;
45
+
46
+ const meta = Ember.meta(this);
47
+ meta.hasMixin = (mixin: Object) => {
48
+ if (mixin === ArrayMixin) {
49
+ return true;
50
+ }
51
+ return false;
52
+ };
44
53
  }
45
54
 
46
55
  //---- Methods/Properties on ArrayProxy that we will keep as our API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/model",
3
- "version": "4.1.0-beta.0",
3
+ "version": "4.1.0",
4
4
  "description": "The default blueprint for ember-cli addons.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -18,9 +18,9 @@
18
18
  "test:node": "mocha"
19
19
  },
20
20
  "dependencies": {
21
- "@ember-data/canary-features": "4.1.0-beta.0",
22
- "@ember-data/private-build-infra": "4.1.0-beta.0",
23
- "@ember-data/store": "4.1.0-beta.0",
21
+ "@ember-data/canary-features": "4.1.0",
22
+ "@ember-data/private-build-infra": "4.1.0",
23
+ "@ember-data/store": "4.1.0",
24
24
  "@ember/edition-utils": "^1.2.0",
25
25
  "@ember/string": "^3.0.0",
26
26
  "ember-auto-import": "^2.2.4",
@@ -33,7 +33,7 @@
33
33
  "inflection": "~1.13.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@ember-data/unpublished-test-infra": "4.1.0-beta.0",
36
+ "@ember-data/unpublished-test-infra": "4.1.0",
37
37
  "@ember/optional-features": "^2.0.0",
38
38
  "@ember/test-helpers": "^2.6.0",
39
39
  "broccoli-asset-rev": "^3.0.0",