diff --git a/text/0000-custom-model-classes.md b/text/0000-custom-model-classes.md index c31e97ad82..e6ae91c2b5 100644 --- a/text/0000-custom-model-classes.md +++ b/text/0000-custom-model-classes.md @@ -36,9 +36,9 @@ We will need five separate changes: - Replacement of few store methods that take DS.Models - Deprecate passing DS.Model classes to adapter/serializers/exposing them on Snapshots -## Instantiating custom Records +## Instantiating and destroying custom Records -First we need to expose a method on the store for instantiating a record, and way for the record to get notified when RecordData values change: +First we need to expose a method on the store for instantiating a record, a hook to be notified when a record is being destroyed for potential cleanup and a way for the record to get notified when RecordData values change: ```ts interface RecordDataWrapper { // proxies a subset of RD methods and hides the rest @@ -79,6 +79,8 @@ class Store { createRecordArgs: { [key: string]: any }, // args passed in to store.createRecord() and processed by recordData to be set on creation recordDataFor: RecordDataFor, notificationManager: NotificationManager): unknown + + willDestroyRecord(record): void } ``` @@ -129,7 +131,6 @@ interface AttributesDefinition { [key: string]: AttributeDefinition } - interface SchemaDefinitionService { // Following the existing RD implementation attributesDefinitonFor(identifier: RecordIdentifier | type: string): AttributesDefiniton @@ -146,22 +147,27 @@ class Store { getSchemaDefinitionService(): SchemaDefinitionService } ``` - -## Replacing Store methods that deal with DS.Model +## Adding store methods for manipulating records + +Currently there exist methods on DS.Model that call into `internalModel` for it's functionality. In order for a parallel implementation +to be possible, we need to expose that functionality through public methods on the store. ```ts class Store { - // deprecate - scheduleSave(model: DS.Model): Promise - reload(model: DS.Model): Promise - relationshipReferenceFor(model: DS.Model): Reference - - - // replace with - scheduleSave(identifier: RecordIdentifier): Promise - reload(identifier: RecordIdentifier): Promise - relationshipReferenceFor(identifier: RecordIdentifier): Reference + saveRecord(record): Promise // equivalent of currently doing record.save() + serializeRecord(record): any // equivalent of currently doing record.serialize() + relationshipReferenceFor(identifier: RecordIdentifier, key: string): RelationshipReference +} +``` + +this would allow you to have a custom model class like this: + +```ts +class CustomModel { + save() { + return this._store.saveRecord(this); + } } ```