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

Custom Model Classes #6313

Merged
merged 1 commit into from
Aug 20, 2019
Merged

Custom Model Classes #6313

merged 1 commit into from
Aug 20, 2019

Conversation

igorT
Copy link
Member

@igorT igorT commented Aug 6, 2019

Implements RFC emberjs/rfcs#487

@igorT igorT changed the title Igor/custom model WIP Igor/custom model Aug 6, 2019
@igorT igorT changed the title WIP Igor/custom model Custom Model Classes Aug 9, 2019
@igorT igorT force-pushed the igor/custom-model branch 3 times, most recently from a74c055 to 89c5f63 Compare August 12, 2019 17:13
packages/store/addon/-private/system/ds-model-store.ts Outdated Show resolved Hide resolved
packages/store/addon/-private/system/core-store.ts Outdated Show resolved Hide resolved
packages/store/addon/-private/system/core-store.ts Outdated Show resolved Hide resolved
packages/store/addon/-private/system/core-store.ts Outdated Show resolved Hide resolved
@igorT igorT force-pushed the igor/custom-model branch from 353cfcd to 4a4c310 Compare August 12, 2019 21:00
type Primitive = string | number | boolean | null;
interface Object {
[member: string]: Value | undefined | ((...args: any[]) => any);
}
interface Arr extends Array<Object | Arr | undefined> {}

type Value = Primitive | Object | Arr;
*/

export type Record = Object;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to RecordInstance in a new PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

*/

export default interface RecordDataRecordWrapper {
rollbackAttributes(): string[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once we have the proxy we need to ensure it is in the ts-upgrade-map

@@ -52,6 +51,14 @@ export default class RecordDataStoreWrapper implements IRecordDataStoreWrapper {
_scheduleManyArrayUpdate(modelName: string, id: string | null, clientId: string, key: string): void;
_scheduleManyArrayUpdate(modelName: string, id: string, clientId: string | null | undefined, key: string): void;
_scheduleManyArrayUpdate(modelName: string, id: string | null, clientId: string | null | undefined, key: string) {
if (!hasValidId(id, clientId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this goes away if we land #6289

this._id = id;
}

get fields(): Map<string, 'attribute' | 'belongsTo' | 'hasMany'> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should fast follow a deprecation, I believe as part of the RFC we were looking at the shim being a place to do. Seems good to have full API support at the beginning though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

get relationshipsByName(): Map<string, RelationshipSchema> {
let relationships = this.store._relationshipsDefinitionFor(this.modelName, this._id);
//TODO Talk to mnorth about needing a cast
return new Map(Object.entries(relationships) as [string, RelationshipSchema][]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we worried about these being uncached getters?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can't cache we should document why we can't assume cacheable and how users should approach using these APIs when they are cacheable.

@@ -2737,21 +2840,36 @@ class Store extends Service {
// contains unknown attributes or relationships, log a warning.

if (ENV.DS_WARN_ON_UNKNOWN_KEYS) {
let modelClass = this.modelFor(modelName);
let unknownAttributes, unknownRelationships;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will only work for the case where the schemas for all type are identical, not the one where they may differ by identifier.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is a low priority fix)

}
}

_attributesDefinitionFor(modelName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double-check the identifiers codepath for retrieving attributes does not pull from this info

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same for relationships definition)

Copy link
Contributor

@mike-north mike-north left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than explicit notes/comments, TS LGTM


export interface SchemaDefinitionService {
doesTypeExist(modelName: string): boolean;
attributesDefinitionFor(identifier: RecordIdentifier | string): AttributesSchema;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit, overloads would allow separate variable name and documentation for the modelName case

const Tag = DS.Model.extend({
name: DS.attr('string'),
people: DS.hasMany('person'),
peopleDidChange: observer('people', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be very careful with this one, possibly confirm with some apps powering their selects with hasMany's that this doesn't break them.

@igorT igorT force-pushed the igor/custom-model branch from 2d48433 to f720741 Compare August 13, 2019 20:58
Copy link
Contributor

@runspired runspired left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall 👍 assuming comments are all resolved

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to ensure that CI is green before landing this.

@igorT igorT force-pushed the igor/custom-model branch 5 times, most recently from ce76ce0 to 327ac50 Compare August 19, 2019 19:41
@igorT
Copy link
Member Author

igorT commented Aug 19, 2019

@rwjblue CI is green

@igorT igorT dismissed rwjblue’s stale review August 19, 2019 21:51

CI green, request invalid ;)

travis allow failures

allo fail chaneg tracker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants