@ember-data/model 4.1.0 → 4.2.0-alpha.3

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.
@@ -2,7 +2,6 @@ import { assert } from '@ember/debug';
2
2
  import { computed } from '@ember/object';
3
3
  import { DEBUG } from '@glimmer/env';
4
4
 
5
- import { RECORD_DATA_ERRORS } from '@ember-data/canary-features';
6
5
  import { recordDataFor } from '@ember-data/store/-private';
7
6
 
8
7
  import { computedMacroWithOptionalParams } from './util';
@@ -151,15 +150,13 @@ function attr(type, options) {
151
150
  );
152
151
  }
153
152
  }
154
- if (RECORD_DATA_ERRORS) {
155
- if (!this.isValid) {
156
- let oldValue = this._internalModel._recordData.getAttr(key);
157
- if (oldValue !== value) {
158
- const { errors } = this;
159
- if (errors.get(key)) {
160
- errors.remove(key);
161
- this.___recordState.cleanErrorRequests();
162
- }
153
+ if (!this.isValid) {
154
+ let oldValue = this._internalModel._recordData.getAttr(key);
155
+ if (oldValue !== value) {
156
+ const { errors } = this;
157
+ if (errors.get(key)) {
158
+ errors.remove(key);
159
+ this.___recordState.cleanErrorRequests();
163
160
  }
164
161
  }
165
162
  }
@@ -12,11 +12,9 @@ import { DEBUG } from '@glimmer/env';
12
12
  import { tracked } from '@glimmer/tracking';
13
13
  import Ember from 'ember';
14
14
 
15
- import { CUSTOM_MODEL_CLASS, RECORD_DATA_ERRORS, REQUEST_SERVICE } from '@ember-data/canary-features';
16
15
  import { HAS_DEBUG_PACKAGE } from '@ember-data/private-build-infra';
17
16
  import {
18
17
  DEPRECATE_EVENTED_API_USAGE,
19
- DEPRECATE_MODEL_TOJSON,
20
18
  DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS,
21
19
  } from '@ember-data/private-build-infra/deprecations';
22
20
  import {
@@ -34,15 +32,6 @@ import { relationshipFromMeta } from './system/relationships/relationship-meta';
34
32
 
35
33
  const { changeProperties } = Ember;
36
34
 
37
- /*
38
- In the non-CUSTOM_MODEL_CLASS world things decorated with flagToggledDecorator
39
- have logic that requires a cache and caching key (which tagged provides), but
40
- in the CUSTOM_MODEL_CLASS branch it only requires dependentKeyCompat which
41
- ensures computeds/observers on the field will fire when anything it accesses
42
- that is tracked changes
43
- */
44
- const flagToggledDecorator = CUSTOM_MODEL_CLASS ? dependentKeyCompat : tagged;
45
-
46
35
  function findPossibleInverses(type, inverseType, name, relationshipsSoFar) {
47
36
  let possibleRelationships = relationshipsSoFar || [];
48
37
 
@@ -78,7 +67,7 @@ function findPossibleInverses(type, inverseType, name, relationshipsSoFar) {
78
67
 
79
68
  /*
80
69
  * This decorator allows us to lazily compute
81
- * an expensive getter on first-access and therafter
70
+ * an expensive getter on first-access and thereafter
82
71
  * never recompute it.
83
72
  */
84
73
  function computeOnce(target, key, desc) {
@@ -132,9 +121,7 @@ class Model extends EmberObject {
132
121
  }
133
122
  }
134
123
 
135
- if (CUSTOM_MODEL_CLASS) {
136
- this.___recordState = new RecordState(this);
137
- }
124
+ this.___recordState = new RecordState(this);
138
125
  this.setProperties(createProps);
139
126
  }
140
127
 
@@ -390,21 +377,13 @@ class Model extends EmberObject {
390
377
  @type {Boolean}
391
378
  @readOnly
392
379
  */
393
- @flagToggledDecorator
380
+ @dependentKeyCompat
394
381
  get isError() {
395
- if (REQUEST_SERVICE) {
396
- return this.currentState.isError;
397
- }
398
- let tag = peekTag(this, 'isError');
399
- tag.value = tag.value || false;
400
- return tag.value;
382
+ return this.currentState.isError;
401
383
  }
402
384
  set isError(v) {
403
- if (REQUEST_SERVICE && DEBUG) {
404
- throw new Error(`isError is not directly settable when REQUEST_SERVICE is enabled`);
405
- } else {
406
- let tag = peekTag(this, 'isError');
407
- tag.value = v;
385
+ if (DEBUG) {
386
+ throw new Error(`isError is not directly settable`);
408
387
  }
409
388
  }
410
389
 
@@ -473,19 +452,10 @@ class Model extends EmberObject {
473
452
  */
474
453
  @tagged
475
454
  get currentState() {
476
- if (CUSTOM_MODEL_CLASS) {
477
- return this.___recordState;
478
- }
479
- if (this.isDestroyed || this.isDestroying) {
480
- return this._internalModel._previousState;
481
- }
482
-
483
- return this._internalModel && this._internalModel.currentState;
455
+ return this.___recordState;
484
456
  }
485
- set currentState(v) {
486
- if (!CUSTOM_MODEL_CLASS) {
487
- this.notifyPropertyChange('currentState');
488
- }
457
+ set currentState(_v) {
458
+ throw new Error('cannot set currentState');
489
459
  }
490
460
 
491
461
  /**
@@ -565,21 +535,19 @@ class Model extends EmberObject {
565
535
  this._internalModel.send('becameValid');
566
536
  }
567
537
  );
568
- if (RECORD_DATA_ERRORS) {
569
- // TODO we should unify how errors gets populated
570
- // with the code managing the update. Probably a
571
- // lazy flush similar to retrieveLatest in ManyArray
572
- let recordData = recordDataFor(this);
573
- let jsonApiErrors;
574
- if (recordData.getErrors) {
575
- jsonApiErrors = recordData.getErrors();
576
- if (jsonApiErrors) {
577
- let errorsHash = errorsArrayToHash(jsonApiErrors);
578
- let errorKeys = Object.keys(errorsHash);
579
-
580
- for (let i = 0; i < errorKeys.length; i++) {
581
- errors._add(errorKeys[i], errorsHash[errorKeys[i]]);
582
- }
538
+ // TODO we should unify how errors gets populated
539
+ // with the code managing the update. Probably a
540
+ // lazy flush similar to retrieveLatest in ManyArray
541
+ let recordData = recordDataFor(this);
542
+ let jsonApiErrors;
543
+ if (recordData.getErrors) {
544
+ jsonApiErrors = recordData.getErrors();
545
+ if (jsonApiErrors) {
546
+ let errorsHash = errorsArrayToHash(jsonApiErrors);
547
+ let errorKeys = Object.keys(errorsHash);
548
+
549
+ for (let i = 0; i < errorKeys.length; i++) {
550
+ errors._add(errorKeys[i], errorsHash[errorKeys[i]]);
583
551
  }
584
552
  }
585
553
  }
@@ -594,22 +562,12 @@ class Model extends EmberObject {
594
562
  @public
595
563
  @type {AdapterError}
596
564
  */
597
- @flagToggledDecorator
565
+ @dependentKeyCompat
598
566
  get adapterError() {
599
- if (REQUEST_SERVICE) {
600
- return this.currentState.adapterError;
601
- }
602
- let tag = peekTag(this, 'adapterError');
603
- tag.value = tag.value || null;
604
- return tag.value;
567
+ return this.currentState.adapterError;
605
568
  }
606
569
  set adapterError(v) {
607
- if (REQUEST_SERVICE && DEBUG) {
608
- throw new Error(`adapterError is not directly settable when REQUEST_SERVICE is enabled`);
609
- } else {
610
- let tag = peekTag(this, 'adapterError');
611
- tag.value = v;
612
- }
570
+ throw new Error(`adapterError is not directly settable`);
613
571
  }
614
572
 
615
573
  /**
@@ -767,11 +725,7 @@ class Model extends EmberObject {
767
725
  @public
768
726
  */
769
727
  deleteRecord() {
770
- if (CUSTOM_MODEL_CLASS) {
771
- this.store.deleteRecord(this);
772
- } else {
773
- this._internalModel.deleteRecord();
774
- }
728
+ this.store.deleteRecord(this);
775
729
  }
776
730
 
777
731
  /**
@@ -840,11 +794,7 @@ class Model extends EmberObject {
840
794
  if (this.isDestroyed) {
841
795
  return;
842
796
  }
843
- if (CUSTOM_MODEL_CLASS) {
844
- this.store.unloadRecord(this);
845
- } else {
846
- this._internalModel.unloadRecord();
847
- }
797
+ this.store.unloadRecord(this);
848
798
  }
849
799
 
850
800
  /**
@@ -934,9 +884,7 @@ class Model extends EmberObject {
934
884
  */
935
885
  rollbackAttributes() {
936
886
  this._internalModel.rollbackAttributes();
937
- if (CUSTOM_MODEL_CLASS) {
938
- this.currentState.cleanErrorRequests();
939
- }
887
+ this.currentState.cleanErrorRequests();
940
888
  }
941
889
 
942
890
  /**
@@ -1870,7 +1818,7 @@ class Model extends EmberObject {
1870
1818
 
1871
1819
  ```javascript
1872
1820
  import { get } from '@ember/object';
1873
- import Blog from 'app/models/blog'
1821
+ import Person from 'app/models/person'
1874
1822
 
1875
1823
  let attributes = Person.attributes
1876
1824
 
@@ -2177,47 +2125,6 @@ if (DEPRECATE_EVENTED_API_USAGE) {
2177
2125
  });
2178
2126
  }
2179
2127
 
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
-
2221
2128
  if (DEBUG) {
2222
2129
  let lookupDescriptor = function lookupDescriptor(obj, keyName) {
2223
2130
  let current = obj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/model",
3
- "version": "4.1.0",
3
+ "version": "4.2.0-alpha.3",
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",
22
- "@ember-data/private-build-infra": "4.1.0",
23
- "@ember-data/store": "4.1.0",
21
+ "@ember-data/canary-features": "4.2.0-alpha.3",
22
+ "@ember-data/private-build-infra": "4.2.0-alpha.3",
23
+ "@ember-data/store": "4.2.0-alpha.3",
24
24
  "@ember/edition-utils": "^1.2.0",
25
25
  "@ember/string": "^3.0.0",
26
26
  "ember-auto-import": "^2.2.4",
@@ -33,23 +33,23 @@
33
33
  "inflection": "~1.13.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@ember-data/unpublished-test-infra": "4.1.0",
36
+ "@ember-data/unpublished-test-infra": "4.2.0-alpha.3",
37
37
  "@ember/optional-features": "^2.0.0",
38
38
  "@ember/test-helpers": "^2.6.0",
39
39
  "broccoli-asset-rev": "^3.0.0",
40
- "ember-cli": "~3.26.1",
40
+ "ember-cli": "~4.0.1",
41
41
  "ember-cli-blueprint-test-helpers": "^0.19.1",
42
42
  "ember-cli-dependency-checker": "^3.2.0",
43
- "ember-cli-htmlbars": "^5.1.2",
43
+ "ember-cli-htmlbars": "^6.0.1",
44
44
  "ember-cli-inject-live-reload": "^2.0.2",
45
45
  "ember-cli-sri": "^2.1.1",
46
46
  "ember-cli-terser": "~4.0.1",
47
47
  "ember-disable-prototype-extensions": "^1.1.3",
48
48
  "ember-export-application-global": "^2.0.1",
49
49
  "ember-load-initializers": "^2.1.1",
50
- "ember-maybe-import-regenerator": "^0.1.6",
50
+ "ember-maybe-import-regenerator": "^1.0.0",
51
51
  "ember-qunit": "^5.1.5",
52
- "ember-resolver": "^8.0.0",
52
+ "ember-resolver": "^8.0.3",
53
53
  "ember-source": "~4.0.0",
54
54
  "ember-source-channel-url": "^3.0.0",
55
55
  "ember-try": "^1.4.0",