Skip to content

Commit

Permalink
public methods on store
Browse files Browse the repository at this point in the history
  • Loading branch information
igorT committed Jun 19, 2019
1 parent 2d532e2 commit c6c4e85
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions text/0000-custom-model-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
```

Expand Down Expand Up @@ -129,7 +131,6 @@ interface AttributesDefinition {
[key: string]: AttributeDefinition
}


interface SchemaDefinitionService {
// Following the existing RD implementation
attributesDefinitonFor(identifier: RecordIdentifier | type: string): AttributesDefiniton
Expand All @@ -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);
}
}
```

Expand Down

0 comments on commit c6c4e85

Please sign in to comment.