@ember-data/model 4.2.0-alpha.8 → 4.2.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.
@@ -2,6 +2,7 @@ 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';
5
6
  import { recordDataFor } from '@ember-data/store/-private';
6
7
 
7
8
  import { computedMacroWithOptionalParams } from './util';
@@ -150,13 +151,15 @@ function attr(type, options) {
150
151
  );
151
152
  }
152
153
  }
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();
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
+ }
160
163
  }
161
164
  }
162
165
  }
@@ -12,6 +12,7 @@ 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';
15
16
  import { HAS_DEBUG_PACKAGE } from '@ember-data/private-build-infra';
16
17
  import {
17
18
  DEPRECATE_EVENTED_API_USAGE,
@@ -32,6 +33,15 @@ import { relationshipFromMeta } from './system/relationships/relationship-meta';
32
33
 
33
34
  const { changeProperties } = Ember;
34
35
 
36
+ /*
37
+ In the non-CUSTOM_MODEL_CLASS world things decorated with flagToggledDecorator
38
+ have logic that requires a cache and caching key (which tagged provides), but
39
+ in the CUSTOM_MODEL_CLASS branch it only requires dependentKeyCompat which
40
+ ensures computeds/observers on the field will fire when anything it accesses
41
+ that is tracked changes
42
+ */
43
+ const flagToggledDecorator = CUSTOM_MODEL_CLASS ? dependentKeyCompat : tagged;
44
+
35
45
  function findPossibleInverses(type, inverseType, name, relationshipsSoFar) {
36
46
  let possibleRelationships = relationshipsSoFar || [];
37
47
 
@@ -121,7 +131,9 @@ class Model extends EmberObject {
121
131
  }
122
132
  }
123
133
 
124
- this.___recordState = new RecordState(this);
134
+ if (CUSTOM_MODEL_CLASS) {
135
+ this.___recordState = new RecordState(this);
136
+ }
125
137
  this.setProperties(createProps);
126
138
  }
127
139
 
@@ -377,13 +389,21 @@ class Model extends EmberObject {
377
389
  @type {Boolean}
378
390
  @readOnly
379
391
  */
380
- @dependentKeyCompat
392
+ @flagToggledDecorator
381
393
  get isError() {
382
- return this.currentState.isError;
394
+ if (REQUEST_SERVICE) {
395
+ return this.currentState.isError;
396
+ }
397
+ let tag = peekTag(this, 'isError');
398
+ tag.value = tag.value || false;
399
+ return tag.value;
383
400
  }
384
401
  set isError(v) {
385
- if (DEBUG) {
386
- throw new Error(`isError is not directly settable`);
402
+ if (REQUEST_SERVICE && DEBUG) {
403
+ throw new Error(`isError is not directly settable when REQUEST_SERVICE is enabled`);
404
+ } else {
405
+ let tag = peekTag(this, 'isError');
406
+ tag.value = v;
387
407
  }
388
408
  }
389
409
 
@@ -452,10 +472,19 @@ class Model extends EmberObject {
452
472
  */
453
473
  @tagged
454
474
  get currentState() {
455
- return this.___recordState;
475
+ if (CUSTOM_MODEL_CLASS) {
476
+ return this.___recordState;
477
+ }
478
+ if (this.isDestroyed || this.isDestroying) {
479
+ return this._internalModel._previousState;
480
+ }
481
+
482
+ return this._internalModel && this._internalModel.currentState;
456
483
  }
457
- set currentState(_v) {
458
- throw new Error('cannot set currentState');
484
+ set currentState(v) {
485
+ if (!CUSTOM_MODEL_CLASS) {
486
+ this.notifyPropertyChange('currentState');
487
+ }
459
488
  }
460
489
 
461
490
  /**
@@ -535,19 +564,21 @@ class Model extends EmberObject {
535
564
  this._internalModel.send('becameValid');
536
565
  }
537
566
  );
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]]);
567
+ if (RECORD_DATA_ERRORS) {
568
+ // TODO we should unify how errors gets populated
569
+ // with the code managing the update. Probably a
570
+ // lazy flush similar to retrieveLatest in ManyArray
571
+ let recordData = recordDataFor(this);
572
+ let jsonApiErrors;
573
+ if (recordData.getErrors) {
574
+ jsonApiErrors = recordData.getErrors();
575
+ if (jsonApiErrors) {
576
+ let errorsHash = errorsArrayToHash(jsonApiErrors);
577
+ let errorKeys = Object.keys(errorsHash);
578
+
579
+ for (let i = 0; i < errorKeys.length; i++) {
580
+ errors._add(errorKeys[i], errorsHash[errorKeys[i]]);
581
+ }
551
582
  }
552
583
  }
553
584
  }
@@ -562,12 +593,22 @@ class Model extends EmberObject {
562
593
  @public
563
594
  @type {AdapterError}
564
595
  */
565
- @dependentKeyCompat
596
+ @flagToggledDecorator
566
597
  get adapterError() {
567
- return this.currentState.adapterError;
598
+ if (REQUEST_SERVICE) {
599
+ return this.currentState.adapterError;
600
+ }
601
+ let tag = peekTag(this, 'adapterError');
602
+ tag.value = tag.value || null;
603
+ return tag.value;
568
604
  }
569
605
  set adapterError(v) {
570
- throw new Error(`adapterError is not directly settable`);
606
+ if (REQUEST_SERVICE && DEBUG) {
607
+ throw new Error(`adapterError is not directly settable when REQUEST_SERVICE is enabled`);
608
+ } else {
609
+ let tag = peekTag(this, 'adapterError');
610
+ tag.value = v;
611
+ }
571
612
  }
572
613
 
573
614
  /**
@@ -725,7 +766,11 @@ class Model extends EmberObject {
725
766
  @public
726
767
  */
727
768
  deleteRecord() {
728
- this.store.deleteRecord(this);
769
+ if (CUSTOM_MODEL_CLASS) {
770
+ this.store.deleteRecord(this);
771
+ } else {
772
+ this._internalModel.deleteRecord();
773
+ }
729
774
  }
730
775
 
731
776
  /**
@@ -794,7 +839,11 @@ class Model extends EmberObject {
794
839
  if (this.isDestroyed) {
795
840
  return;
796
841
  }
797
- this.store.unloadRecord(this);
842
+ if (CUSTOM_MODEL_CLASS) {
843
+ this.store.unloadRecord(this);
844
+ } else {
845
+ this._internalModel.unloadRecord();
846
+ }
798
847
  }
799
848
 
800
849
  /**
@@ -884,7 +933,9 @@ class Model extends EmberObject {
884
933
  */
885
934
  rollbackAttributes() {
886
935
  this._internalModel.rollbackAttributes();
887
- this.currentState.cleanErrorRequests();
936
+ if (CUSTOM_MODEL_CLASS) {
937
+ this.currentState.cleanErrorRequests();
938
+ }
888
939
  }
889
940
 
890
941
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/model",
3
- "version": "4.2.0-alpha.8",
3
+ "version": "4.2.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.2.0-alpha.8",
22
- "@ember-data/private-build-infra": "4.2.0-alpha.8",
23
- "@ember-data/store": "4.2.0-alpha.8",
21
+ "@ember-data/canary-features": "4.2.0",
22
+ "@ember-data/private-build-infra": "4.2.0",
23
+ "@ember-data/store": "4.2.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,29 +33,29 @@
33
33
  "inflection": "~1.13.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@ember-data/unpublished-test-infra": "4.2.0-alpha.8",
36
+ "@ember-data/unpublished-test-infra": "4.2.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",
40
- "ember-cli": "~4.1.1",
40
+ "ember-cli": "~3.26.1",
41
41
  "ember-cli-blueprint-test-helpers": "^0.19.1",
42
42
  "ember-cli-dependency-checker": "^3.2.0",
43
- "ember-cli-htmlbars": "^6.0.1",
43
+ "ember-cli-htmlbars": "^5.1.2",
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": "^1.0.0",
50
+ "ember-maybe-import-regenerator": "^0.1.6",
51
51
  "ember-qunit": "^5.1.5",
52
- "ember-resolver": "^8.0.3",
52
+ "ember-resolver": "^8.0.0",
53
53
  "ember-source": "~4.0.0",
54
54
  "ember-source-channel-url": "^3.0.0",
55
55
  "ember-try": "^1.4.0",
56
56
  "loader.js": "^4.7.0",
57
57
  "qunit": "^2.15.0",
58
- "qunit-dom": "^2.0.0",
58
+ "qunit-dom": "^1.6.0",
59
59
  "silent-error": "^1.1.1",
60
60
  "webpack": "^5.37.1"
61
61
  },