@ember-data/model 4.2.0-alpha.0 → 4.2.0-alpha.4

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
  }
@@ -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
 
@@ -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
 
@@ -118,8 +108,10 @@ function computeOnce(target, key, desc) {
118
108
  @uses DeprecatedEvented
119
109
  */
120
110
  class Model extends EmberObject {
121
- init(...args) {
122
- super.init(...args);
111
+ init(options = {}) {
112
+ const createProps = options._createProps;
113
+ delete options._createProps;
114
+ super.init(options);
123
115
 
124
116
  if (DEBUG) {
125
117
  if (!this._internalModel) {
@@ -129,9 +121,8 @@ class Model extends EmberObject {
129
121
  }
130
122
  }
131
123
 
132
- if (CUSTOM_MODEL_CLASS) {
133
- this.___recordState = new RecordState(this);
134
- }
124
+ this.___recordState = new RecordState(this);
125
+ this.setProperties(createProps);
135
126
  }
136
127
 
137
128
  /**
@@ -386,21 +377,13 @@ class Model extends EmberObject {
386
377
  @type {Boolean}
387
378
  @readOnly
388
379
  */
389
- @flagToggledDecorator
380
+ @dependentKeyCompat
390
381
  get isError() {
391
- if (REQUEST_SERVICE) {
392
- return this.currentState.isError;
393
- }
394
- let tag = peekTag(this, 'isError');
395
- tag.value = tag.value || false;
396
- return tag.value;
382
+ return this.currentState.isError;
397
383
  }
398
384
  set isError(v) {
399
- if (REQUEST_SERVICE && DEBUG) {
400
- throw new Error(`isError is not directly settable when REQUEST_SERVICE is enabled`);
401
- } else {
402
- let tag = peekTag(this, 'isError');
403
- tag.value = v;
385
+ if (DEBUG) {
386
+ throw new Error(`isError is not directly settable`);
404
387
  }
405
388
  }
406
389
 
@@ -469,19 +452,10 @@ class Model extends EmberObject {
469
452
  */
470
453
  @tagged
471
454
  get currentState() {
472
- if (CUSTOM_MODEL_CLASS) {
473
- return this.___recordState;
474
- }
475
- if (this.isDestroyed || this.isDestroying) {
476
- return this._internalModel._previousState;
477
- }
478
-
479
- return this._internalModel && this._internalModel.currentState;
455
+ return this.___recordState;
480
456
  }
481
- set currentState(v) {
482
- if (!CUSTOM_MODEL_CLASS) {
483
- this.notifyPropertyChange('currentState');
484
- }
457
+ set currentState(_v) {
458
+ throw new Error('cannot set currentState');
485
459
  }
486
460
 
487
461
  /**
@@ -561,21 +535,19 @@ class Model extends EmberObject {
561
535
  this._internalModel.send('becameValid');
562
536
  }
563
537
  );
564
- if (RECORD_DATA_ERRORS) {
565
- // TODO we should unify how errors gets populated
566
- // with the code managing the update. Probably a
567
- // lazy flush similar to retrieveLatest in ManyArray
568
- let recordData = recordDataFor(this);
569
- let jsonApiErrors;
570
- if (recordData.getErrors) {
571
- jsonApiErrors = recordData.getErrors();
572
- if (jsonApiErrors) {
573
- let errorsHash = errorsArrayToHash(jsonApiErrors);
574
- let errorKeys = Object.keys(errorsHash);
575
-
576
- for (let i = 0; i < errorKeys.length; i++) {
577
- errors._add(errorKeys[i], errorsHash[errorKeys[i]]);
578
- }
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]]);
579
551
  }
580
552
  }
581
553
  }
@@ -590,22 +562,12 @@ class Model extends EmberObject {
590
562
  @public
591
563
  @type {AdapterError}
592
564
  */
593
- @flagToggledDecorator
565
+ @dependentKeyCompat
594
566
  get adapterError() {
595
- if (REQUEST_SERVICE) {
596
- return this.currentState.adapterError;
597
- }
598
- let tag = peekTag(this, 'adapterError');
599
- tag.value = tag.value || null;
600
- return tag.value;
567
+ return this.currentState.adapterError;
601
568
  }
602
569
  set adapterError(v) {
603
- if (REQUEST_SERVICE && DEBUG) {
604
- throw new Error(`adapterError is not directly settable when REQUEST_SERVICE is enabled`);
605
- } else {
606
- let tag = peekTag(this, 'adapterError');
607
- tag.value = v;
608
- }
570
+ throw new Error(`adapterError is not directly settable`);
609
571
  }
610
572
 
611
573
  /**
@@ -763,11 +725,7 @@ class Model extends EmberObject {
763
725
  @public
764
726
  */
765
727
  deleteRecord() {
766
- if (CUSTOM_MODEL_CLASS) {
767
- this.store.deleteRecord(this);
768
- } else {
769
- this._internalModel.deleteRecord();
770
- }
728
+ this.store.deleteRecord(this);
771
729
  }
772
730
 
773
731
  /**
@@ -836,11 +794,7 @@ class Model extends EmberObject {
836
794
  if (this.isDestroyed) {
837
795
  return;
838
796
  }
839
- if (CUSTOM_MODEL_CLASS) {
840
- this.store.unloadRecord(this);
841
- } else {
842
- this._internalModel.unloadRecord();
843
- }
797
+ this.store.unloadRecord(this);
844
798
  }
845
799
 
846
800
  /**
@@ -930,9 +884,7 @@ class Model extends EmberObject {
930
884
  */
931
885
  rollbackAttributes() {
932
886
  this._internalModel.rollbackAttributes();
933
- if (CUSTOM_MODEL_CLASS) {
934
- this.currentState.cleanErrorRequests();
935
- }
887
+ this.currentState.cleanErrorRequests();
936
888
  }
937
889
 
938
890
  /**
@@ -2075,6 +2027,7 @@ class Model extends EmberObject {
2075
2027
  // the values initialized during create to `setUnknownProperty`
2076
2028
  Model.prototype._internalModel = null;
2077
2029
  Model.prototype.store = null;
2030
+ Model.prototype._createProps = null;
2078
2031
 
2079
2032
  if (HAS_DEBUG_PACKAGE) {
2080
2033
  /**
@@ -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.2.0-alpha.0",
3
+ "version": "4.2.0-alpha.4",
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.0",
22
- "@ember-data/private-build-infra": "4.2.0-alpha.0",
23
- "@ember-data/store": "4.2.0-alpha.0",
21
+ "@ember-data/canary-features": "4.2.0-alpha.4",
22
+ "@ember-data/private-build-infra": "4.2.0-alpha.4",
23
+ "@ember-data/store": "4.2.0-alpha.4",
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.2.0-alpha.0",
36
+ "@ember-data/unpublished-test-infra": "4.2.0-alpha.4",
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",