Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:prepare for universal reactivity #8949

Merged
merged 11 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ module.exports = {
'no-restricted-imports': [
'error',
{
paths: ['@glimmer/env', '@ember/utils', '@ember/runloop'],
paths: [
'@glimmer/env',
'@ember/object/compat',
'@glimmer/tracking',
'@glimmer/validator',
'@ember/utils',
'@ember/runloop',
],
},
// '@ember/string',
// '@ember/object',
// '@ember/service',
// '@ember/object/compat',
// 'ember-inflector',
],

Expand Down Expand Up @@ -96,14 +102,18 @@ module.exports = {
'no-restricted-imports': [
'error',
{
paths: ['@glimmer/env', '@ember/utils', '@ember/runloop'],
// patterns: ['@ember/*'],
paths: [
'@glimmer/env',
'@ember/object/compat',
'@glimmer/tracking',
'@glimmer/validator',
'@ember/utils',
'@ember/runloop',
],
},

// '@ember/string',
// '@ember/object',
// '@ember/service',
// '@ember/object/compat',
// 'ember-inflector',
],
},
Expand Down Expand Up @@ -192,7 +202,6 @@ module.exports = {
'packages/unpublished-test-infra/addon-test-support/qunit-asserts/assert-warning.ts',
'packages/unpublished-test-infra/addon-test-support/qunit-asserts/assert-assertion.ts',
'tests/fastboot/types/global.d.ts',
'tests/fastboot/types/fastboot-test-app/index.d.ts',
'tests/fastboot/app/serializers/application.ts',
'tests/fastboot/app/router.ts',
'tests/fastboot/app/resolver.ts',
Expand All @@ -205,7 +214,6 @@ module.exports = {
'@types/ember/index.d.ts',
'@types/@glimmer/tracking.d.ts',
'@types/@ember/utils/index.d.ts',
'@types/@ember/object/compat.d.ts',
'@types/@ember/debug/index.d.ts',
'ember-data-types/q/schema-definition-service.ts',
'ember-data-types/q/record-instance.ts',
Expand Down
16 changes: 7 additions & 9 deletions packages/adapter/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ export default {

external: [
'@embroider/macros',
'@ember/service',
'@ember/service', // inject the store to base Adapter
'@ember-data/store/-private',
'require',
'ember-inflector',
'@ember/debug',
'@ember/string',
'@ember/object',
'@ember/object/mixin',
'@ember/application',
'@ember/polyfills',
'ember-inflector', // pluralize
'@ember/debug', // assert, deprecate
'@ember/string', // dasherize, camelize
'@ember/object', // Adapter base, computed for headers
'@ember/object/mixin', // BuildURLMixin
'@ember/application', // getOwner
],

plugins: [
Expand Down
10 changes: 6 additions & 4 deletions packages/adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,19 @@
your Adapter does not need the method.

```ts
import EmberObject from '@ember/object';

async function fetchData(url, options = {}) {
let response = await fetch(url, options);
return response.toJSON();
}

export default class ApplicationAdapter extends EmberObject {
export default class ApplicationAdapter {
findRecord(_, { modelName }, id) {
return fetchData(`./${modelName}s/${id}`);
}

static create() {
return new this();
}
}
```

Expand Down Expand Up @@ -147,7 +149,7 @@ Note: If you are using Ember and would like to make use of `service` injections
```js
import Store from '@ember-data/store';
import Adapter from '@ember-data/adapter/json-api';
import { getOwner, setOwner } from '@ember/application';
import { getOwner, setOwner } from '@ember/owner';

class extends Store {
#adapter = null;
Expand Down
8 changes: 4 additions & 4 deletions packages/adapter/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ declare const jQuery: JQueryStatic | undefined;
{
"posts": {
"id": 1,
"title": "I'm Running to Reform the W3C's Tag",
"title": "I'm Running to Reform the W3C",
"author": "Yehuda Katz"
}
}
Expand All @@ -129,7 +129,7 @@ declare const jQuery: JQueryStatic | undefined;
"posts": [
{
"id": 1,
"title": "I'm Running to Reform the W3C's Tag",
"title": "I'm Running to Reform the W3C",
"author": "Yehuda Katz"
},
{
Expand Down Expand Up @@ -187,7 +187,7 @@ declare const jQuery: JQueryStatic | undefined;
{
"posts": {
"id": 5,
"title": "I'm Running to Reform the W3C's Tag",
"title": "I'm Running to Reform the W3C",
"author": "Yehuda Katz",
"comments": [1, 2]
},
Expand All @@ -213,7 +213,7 @@ declare const jQuery: JQueryStatic | undefined;
{
"posts": {
"id": 5,
"title": "I'm Running to Reform the W3C's Tag",
"title": "I'm Running to Reform the W3C",
"author": "Yehuda Katz",
"links": {
"comments": "/posts/5/comments"
Expand Down
9 changes: 1 addition & 8 deletions packages/graph/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ export default {
external: [
'@embroider/macros',
'@ember-data/store/-private',
'@ember/service',
'ember-inflector',
'@ember/debug',
'@ember/string',
'@ember/object',
'@ember/object/mixin',
'@ember/application',
'@ember/polyfills',
'@ember/debug', // assert, deprecate
],

plugins: [
Expand Down
10 changes: 2 additions & 8 deletions packages/json-api/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ export default {
'@ember-data/request-utils',
'@ember-data/store',
'@ember-data/store/-private',
'@ember/application',
'@ember/debug',
'@ember/object',
'@ember/object/mixin',
'@ember/polyfills',
'@ember/service',
'@ember/string',
'@ember/debug', // assert, deprecate
'@embroider/macros',
'ember-inflector',
'ember-inflector', // pluralize
],

plugins: [
Expand Down
13 changes: 12 additions & 1 deletion packages/model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,24 @@
},
"@ember/string": {
"injected": true
},
"@ember-data/tracking": {
"injected": true
},
"@ember-data/graph": {
"injected": true
},
"@ember-data/json-api": {
"injected": true
},
"@ember-data/legacy-compat": {
"injected": true
}
},
"dependencies": {
"@ember-data/private-build-infra": "workspace:5.5.0-alpha.10",
"@ember/edition-utils": "^1.2.0",
"@embroider/macros": "^1.13.2",
"ember-cached-decorator-polyfill": "^1.0.2",
"ember-cli-babel": "^8.1.0",
"ember-cli-string-utils": "^1.1.0",
"ember-cli-test-info": "^1.0.0",
Expand Down
3 changes: 0 additions & 3 deletions packages/model/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ export default {
external: [
'@embroider/macros',
'@ember/service',
'ember',
'ember-inflector',
'@ember/debug',
'@ember/object/computed',
'@ember/object/compat',
'@ember-data/store/-private',
'@ember-data/store',
'@ember/object/internals',
Expand All @@ -32,7 +30,6 @@ export default {
'@ember/object',
'@ember/object/mixin',
'@ember/application',
'@glimmer/tracking',
'@ember/polyfills',
],

Expand Down
3 changes: 1 addition & 2 deletions packages/model/src/-private/has-many.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
@module @ember-data/model
*/
import { A } from '@ember/array';
import { assert, deprecate } from '@ember/debug';
import { computed } from '@ember/object';
import { dasherize } from '@ember/string';
Expand Down Expand Up @@ -205,7 +204,7 @@ function hasMany(type, options) {
}
}
if (this.isDestroying || this.isDestroyed) {
return A();
return [];
}
return lookupLegacySupport(this).getHasMany(key);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ function handleCompletedRelationshipRequest(
// for the async reload case there will be no proxy if the ui
// has never been accessed
if (proxy && !isHasMany) {
// @ts-expect-error unsure why this is not resolving the boolean but async belongsTo is weird
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (proxy.content && proxy.content.isDestroying) {
(proxy as PromiseBelongsTo).set('content', null);
Expand Down
6 changes: 3 additions & 3 deletions packages/model/src/-private/many-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { assert } from '@ember/debug';

import type Store from '@ember-data/store';
import {
IDENTIFIER_ARRAY_TAG,
ARRAY_SIGNAL,
MUTATE,
notifyArray,
RecordArray,
Expand Down Expand Up @@ -275,8 +275,8 @@ export default class RelatedCollection extends RecordArray {
}

notify() {
const tag = this[IDENTIFIER_ARRAY_TAG];
tag.shouldReset = true;
const signal = this[ARRAY_SIGNAL];
signal.shouldReset = true;
// @ts-expect-error
notifyArray(this);
}
Expand Down
5 changes: 1 addition & 4 deletions packages/model/src/-private/model-for-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import Model, { type ModelFactory } from './model';

/*
In case someone defined a relationship to a mixin, for example:
```
import Model, { belongsTo, hasMany } from '@ember-data/model';
import Mixin from '@ember/object/mixin';

```ts
class CommentModel extends Model {
@belongsTo('commentable', { polymorphic: true }) owner;
}
Expand Down
1 change: 0 additions & 1 deletion packages/model/src/-private/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Model extends EmberObject {
deleteRecord(): void;
unloadRecord(): void;
serialize(): Record<string, unknown>;
_notifyProperties(keys: string[]): void;

static modelName: string;
static fields: Map<string, 'attribute' | 'belongsTo' | 'hasMany'>;
Expand Down
Loading