jeudi 28 juin 2018

Ember change normalizeResponse based on queried model

I'm using a second datastore with my Ember app, so I can communicate with a separate external API. I have no control over this API.

With a serializer I can add some missing properties like id:

normalizeResponse(store, primaryModelClass, payload, id, requestType) {
    if (requestType == 'query') {
        payload.forEach(function(el, index) {
            payload[index].id = index
        })
    }

Now I can do some different tricks for each different requestType. But every response is parsed. Now sometimes a response from one request needs to be parsed differently.

So what I am trying to do is change the normalizeResponse functionality for each different request path (mapped to a fake model using pathForType in an adapter for this store). But the argument store is always the same (obviously) and the argument promaryModelClass is always "unknown mixin" - not sure if this can be any help.

How can I find what model was requested? With this information I could do a switch() in normalizeResponse.




Aucun commentaire:

Enregistrer un commentaire