You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Goal: To be able to use computed getters and maybe more on the data returned from the API. E.g.:
constbook=this.api.get().books().items[0]book.releaseDate// automatically cast to whatever date format you wantbook.author().fullName// automatically compiled from `firstName` and `lastName`
The main problem is: How should hal-json-vuex know what getters to expose? How should it know what type of entity the current piece of data represents?
Option 1: We define the entity when retrieving from the API / Vuex, i.e. a decorator pattern. Possible implementations:
this.api.get().lastReadBook(Book) // ok
this.api.get().lastReadBook().as(Book) // hmm...
Book(this.api.get().lastReadBook()) // akward
Option 2: Detect automatically according to the URI. I.e. the developer can define that URIs like '/books/*' always yield a Book. Goes against the idea of HATEOAS.
Option 3: The API sends a special property that defines the entity type. Or, we parse an OpenAPI specification. Not an option in case the developer doesn't control the API implementation.
Option 4: Expose all getters globally on all entities, and if one tries to call author.releaseDate, this fails. Not nice in case of naming conflicts.
Option 5: Allow the developer to define custom rules to determine the entity class that a given piece of data represents, based on self link, relation name that was used to get the entity, and the properties. It could also be done before the data hits the Vuex store, similar to dataTransformers in Vuex ORM. Will be complex to use for developers.
Global Hook (ähnlich wie DataTransformer) on Hal-Json-Vuex Config.
Hook läuft wenn Daten aus VuexStore geladen werden.
Hook-Name Vorschlag: ModelMapping, StoreValueMapper, ...
Hook bekommt Daten aus VuexStore, muss ein Objekt "StoreValueProxy" oder eine Ableitung davon zurückgehen.
Goal: To be able to use computed getters and maybe more on the data returned from the API. E.g.:
The main problem is: How should hal-json-vuex know what getters to expose? How should it know what type of entity the current piece of data represents?
Option 1: We define the entity when retrieving from the API / Vuex, i.e. a decorator pattern. Possible implementations:
Option 2: Detect automatically according to the URI. I.e. the developer can define that URIs like '/books/*' always yield a Book. Goes against the idea of HATEOAS.
Option 3: The API sends a special property that defines the entity type. Or, we parse an OpenAPI specification. Not an option in case the developer doesn't control the API implementation.
Option 4: Expose all getters globally on all entities, and if one tries to call
author.releaseDate
, this fails. Not nice in case of naming conflicts.Option 5: Allow the developer to define custom rules to determine the entity class that a given piece of data represents, based on self link, relation name that was used to get the entity, and the properties. It could also be done before the data hits the Vuex store, similar to dataTransformers in Vuex ORM. Will be complex to use for developers.
Originally posted by @usu in ecamp/ecamp3#507 (comment)
Personally I lean towards option 1 or 5, and both of those could be implemented mostly externally to this library.
The text was updated successfully, but these errors were encountered: