@ember-data/model 4.2.0-alpha.1 → 4.2.0-alpha.2

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,7 +12,6 @@ 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,
@@ -33,15 +32,6 @@ import { relationshipFromMeta } from './system/relationships/relationship-meta';
33
32
 
34
33
  const { changeProperties } = Ember;
35
34
 
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
-
45
35
  function findPossibleInverses(type, inverseType, name, relationshipsSoFar) {
46
36
  let possibleRelationships = relationshipsSoFar || [];
47
37
 
@@ -131,9 +121,7 @@ class Model extends EmberObject {
131
121
  }
132
122
  }
133
123
 
134
- if (CUSTOM_MODEL_CLASS) {
135
- this.___recordState = new RecordState(this);
136
- }
124
+ this.___recordState = new RecordState(this);
137
125
  this.setProperties(createProps);
138
126
  }
139
127
 
@@ -389,21 +377,13 @@ class Model extends EmberObject {
389
377
  @type {Boolean}
390
378
  @readOnly
391
379
  */
392
- @flagToggledDecorator
380
+ @dependentKeyCompat
393
381
  get 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;
382
+ return this.currentState.isError;
400
383
  }
401
384
  set isError(v) {
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;
385
+ if (DEBUG) {
386
+ throw new Error(`isError is not directly settable`);
407
387
  }
408
388
  }
409
389
 
@@ -472,19 +452,10 @@ class Model extends EmberObject {
472
452
  */
473
453
  @tagged
474
454
  get currentState() {
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;
455
+ return this.___recordState;
483
456
  }
484
- set currentState(v) {
485
- if (!CUSTOM_MODEL_CLASS) {
486
- this.notifyPropertyChange('currentState');
487
- }
457
+ set currentState(_v) {
458
+ throw new Error('cannot set currentState');
488
459
  }
489
460
 
490
461
  /**
@@ -564,21 +535,19 @@ class Model extends EmberObject {
564
535
  this._internalModel.send('becameValid');
565
536
  }
566
537
  );
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
- }
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]]);
582
551
  }
583
552
  }
584
553
  }
@@ -593,22 +562,12 @@ class Model extends EmberObject {
593
562
  @public
594
563
  @type {AdapterError}
595
564
  */
596
- @flagToggledDecorator
565
+ @dependentKeyCompat
597
566
  get 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;
567
+ return this.currentState.adapterError;
604
568
  }
605
569
  set adapterError(v) {
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
- }
570
+ throw new Error(`adapterError is not directly settable`);
612
571
  }
613
572
 
614
573
  /**
@@ -766,11 +725,7 @@ class Model extends EmberObject {
766
725
  @public
767
726
  */
768
727
  deleteRecord() {
769
- if (CUSTOM_MODEL_CLASS) {
770
- this.store.deleteRecord(this);
771
- } else {
772
- this._internalModel.deleteRecord();
773
- }
728
+ this.store.deleteRecord(this);
774
729
  }
775
730
 
776
731
  /**
@@ -839,11 +794,7 @@ class Model extends EmberObject {
839
794
  if (this.isDestroyed) {
840
795
  return;
841
796
  }
842
- if (CUSTOM_MODEL_CLASS) {
843
- this.store.unloadRecord(this);
844
- } else {
845
- this._internalModel.unloadRecord();
846
- }
797
+ this.store.unloadRecord(this);
847
798
  }
848
799
 
849
800
  /**
@@ -933,9 +884,7 @@ class Model extends EmberObject {
933
884
  */
934
885
  rollbackAttributes() {
935
886
  this._internalModel.rollbackAttributes();
936
- if (CUSTOM_MODEL_CLASS) {
937
- this.currentState.cleanErrorRequests();
938
- }
887
+ this.currentState.cleanErrorRequests();
939
888
  }
940
889
 
941
890
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/model",
3
- "version": "4.2.0-alpha.1",
3
+ "version": "4.2.0-alpha.2",
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.1",
22
- "@ember-data/private-build-infra": "4.2.0-alpha.1",
23
- "@ember-data/store": "4.2.0-alpha.1",
21
+ "@ember-data/canary-features": "4.2.0-alpha.2",
22
+ "@ember-data/private-build-infra": "4.2.0-alpha.2",
23
+ "@ember-data/store": "4.2.0-alpha.2",
24
24
  "@ember/edition-utils": "^1.2.0",
25
25
  "@ember/string": "^3.0.0",
26
26
  "ember-auto-import": "^2.2.4",
@@ -33,21 +33,21 @@
33
33
  "inflection": "~1.13.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@ember-data/unpublished-test-infra": "4.2.0-alpha.1",
36
+ "@ember-data/unpublished-test-infra": "4.2.0-alpha.2",
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
52
  "ember-resolver": "^8.0.3",
53
53
  "ember-source": "~4.0.0",