Skip to content

Commit 01f9a0d

Browse files
authored
Merge pull request #794 from snewcomer/rfc-642
Simplifying Schema Definition Service type signatures
2 parents c69d2dd + c3c3fae commit 01f9a0d

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
Stage: Accepted
3+
Start Date: 2022-02-12
4+
Release Date: Unreleased
5+
Release Versions:
6+
ember-source: vX.Y.Z
7+
ember-data: vX.Y.Z
8+
Relevant Team(s): ember-data
9+
RFC PR: https://github.com/emberjs/rfcs/pull/794
10+
---
11+
12+
# Simplify Schema Definition Service methods in Ember Data
13+
14+
## Summary
15+
16+
This RFC is an amendment to the Custom Model Classes RFC (https://github.com/emberjs/rfcs/pull/487).
17+
Based on implementation feedback, we discovered we could simplify the arguments to
18+
`attributesDefinitionFor` and `relationshipsDefinitionFor` to drop the string argument and always
19+
pass in an object.
20+
21+
22+
## Motivation
23+
24+
When implementing a schema service, code ends up easier and cleaner if it does not have to deal with
25+
both a raw string and an object.
26+
27+
## Detailed design
28+
29+
The original RFC proposed the following interface:
30+
31+
```typescript
32+
interface SchemaDefinitionService {
33+
// Following the existing RD implementation
34+
attributesDefinitionFor(identifier: RecordIdentifier | type: string): AttributesDefinition
35+
36+
// Following the existing RD implementation
37+
relationshipsDefinitionFor(identifier: RecordIdentifier | type: string): RelationshipsDefinition
38+
doesTypeExist(type: string): boolean
39+
}
40+
```
41+
42+
We can simplify `attributesDefinitionFor` and `relationshipsDefinitionFor` methods to always accept an object.
43+
44+
```typescript
45+
interface SchemaDefinitionService {
46+
// Following the existing RD implementation
47+
attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesDefinition
48+
49+
// Following the existing RD implementation
50+
relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }): RelationshipsDefinition
51+
52+
doesTypeExist(type: string): boolean
53+
}
54+
```
55+
56+
## How we teach this
57+
58+
It simplifies the types passed in, so should be easier to teach.
59+
60+
61+
## Drawbacks
62+
63+
64+
## Alternatives
65+
66+
Keeping the existing design per the original RFC.

0 commit comments

Comments
 (0)