Skip to content

Commit 25bbd4d

Browse files
authored
Merge pull request #1483 from muziejus/de-DS-docs
docs: Remove references to DS and DS imports.
2 parents 9d17480 + 4e52cc7 commit 25bbd4d

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

docs/ember-data/models.md

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ For details about decorator usage, see [our overview of how Ember's decorators w
66

77
## `@attr`
88

9-
The type returned by the `@attr` decorator is whatever [Transform](https://api.emberjs.com/ember-data/release/classes/Transform) is applied via the invocation.
9+
The type returned by the `@attr` decorator is whatever [Transform](https://api.emberjs.com/ember-data/release/classes/Transform) is applied via the invocation. See [our overview of Transforms for more information](./transforms.md).
1010

1111
* If you supply no argument to `@attr`, the value is passed through without transformation.
1212
* If you supply one of the built-in transforms, you will get back a corresponding type:
@@ -70,22 +70,21 @@ import type User from './user';
7070

7171
### `@belongsTo`
7272

73-
The type returned by the `@hasMany` decorator depends on whether the relationship is `{ async: true }` \(which it is by default\).
73+
The type returned by the `@belongsTo` decorator depends on whether the relationship is `{ async: true }` \(which it is by default\).
7474

75-
* If the value is `true`, the type you should use is `DS.PromiseObject<Model>`, where `Model` is the type of the model you are creating a relationship to.
75+
* If the value is `true`, the type you should use is `AsyncBelongsTo<Model>`, where `Model` is the type of the model you are creating a relationship to.
7676
* If the value is `false`, the type is `Model`, where `Model` is the type of the model you are creating a relationship to.
7777

7878
So, for example, you might define a class like this:
7979

8080
```typescript
81-
import Model, { belongsTo } from '@ember-data/model';
82-
import DS from 'ember-data'; // NOTE: this is a workaround, see discussion below!
81+
import Model, { belongsTo, type AsyncBelongsTo } from '@ember-data/model';
8382
import type User from './user';
8483
import type Site from './site';
8584

8685
export default class Post extends Model {
8786
@belongsTo('user')
88-
declare user: DS.PromiseObject<User>;
87+
declare user: AsyncBelongsTo<User>;
8988

9089
@belongsTo('site', { async: false })
9190
declare site: Site;
@@ -94,7 +93,7 @@ export default class Post extends Model {
9493

9594
These are _type_-safe to define as always present, that is to leave off the `?` optional marker:
9695

97-
* accessing an async relationship will always return a `PromiseObject`, which itself may or may not ultimately resolve to a value—depending on the API response—but will always be present itself.
96+
* accessing an async relationship will always return an `AsyncBelongsTo<Model>` object, which itself may or may not ultimately resolve to a value—depending on the API response—but will always be present itself.
9897
* accessing a non-async relationship which is known to be associated but has not been loaded will trigger an error, so all access to the property will be safe _if_ it resolves at all.
9998

10099
Note, however, that this type-safety is not a guarantee of there being no runtime error: you still need to uphold the contract for non-async relationships \(that is: loading the data first, or side-loading it with the request\) to avoid throwing an error!
@@ -103,32 +102,24 @@ Note, however, that this type-safety is not a guarantee of there being no runtim
103102

104103
The type returned by the `@hasMany` decorator depends on whether the relationship is `{ async: true }` \(which it is by default\).
105104

106-
* If the value is `true`, the type you should use is `DS.PromiseManyArray<Model>`, where `Model` is the type of the model you are creating a relationship to.
107-
* If the value is `false`, the type is `EmberArray<Model>`, where `Model` is the type of the model you are creating a relationship to.
105+
* If the value is `true`, the type you should use is `AsyncHasMany<Model>`, where `Model` is the type of the model you are creating a relationship to.
106+
* If the value is `false`, the type is `SyncHasMany<Model>`, where `Model` is the type of the model you are creating a relationship to.
108107

109108
So, for example, you might define a class like this:
110109

111110
```typescript
112-
import Model, { hasMany } from '@ember-data/model';
113-
import EmberArray from '@ember/array';
114-
import DS from 'ember-data'; // NOTE: this is a workaround, see discussion below!
111+
import Model, { hasMany, type AsyncHasMany, type SyncHasMany } from '@ember-data/model';
115112
import type Comment from './comment';
116113
import type User from './user';
117114

118115
export default class Thread extends Model {
119116
@hasMany('comment')
120-
declare comment: DS.PromiseManyArray<Comment>;
117+
declare comment: AsyncHasMany<Comment>;
121118

122119
@hasMany('user', { async: false })
123-
declare participants: EmberArray<User>;
120+
declare participants: SyncHasMany<User>;
124121
}
125122
```
126123

127124
The same basic rules about the safety of these lookups as with `@belongsTo` apply to these types. The difference is just that in `@hasMany` the resulting types are _arrays_ rather than single objects.
128125

129-
## Importing `PromiseObject` and `PromiseManyArray`
130-
131-
There is no public import path in the [Ember Data Packages](https://emberjs.github.io/rfcs/0395-ember-data-packages.html) API for the `PromiseObject` and `PromiseManyArray` types. These types are slowly being disentangled from Ember Data and will eventually be removed. However, until they are, we need a way to refer to them. For _now_, the best option is to refer to them via the legacy `DS` import.
132-
133-
In the future, they will become unnecesary, as the types will simply be `Promise<Model>` and `Promise<Array<Model>>`.
134-

docs/ember-data/transforms.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Transforms
22

3-
`DS.attr` defines an attribute on a [DS.Model](https://guides.emberjs.com/release/models/defining-models/).
3+
In Ember Data, `attr` defines an attribute on a [Model](https://guides.emberjs.com/release/models/defining-models/).
44
By default, attributes are passed through as-is, however you can specify an
55
optional type to have the value automatically transformed.
66
Ember Data ships with four basic transform types: `string`, `number`, `boolean` and `date`.
77

8-
You can define your own transforms by subclassing [DS.Transform](https://guides.emberjs.com/release/models/defining-models/#toc_custom-transforms).
8+
You can define your own transforms by subclassing [Transform](https://guides.emberjs.com/release/models/defining-models/#toc_custom-transforms).
99
Ember Data transforms are normal TypeScript classes.
1010
The return type of `deserialize` method becomes type of the model class property.
1111

0 commit comments

Comments
 (0)