-
-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Description
It would be nice if this plugin would pass the model class as the second argument to the dataTransformer callback so that the dataTransformer function could mutate extra state in the model. Example:
In my model:
export default class FooBar extends Model {
// ....
static state() {
return {
abilities: null,
}
}
}
Now in the transformer:
dataTransformer: (response, model) => {
if ('abilities' in response.data) {
model.commit((state) => {
state.abilities = response.data.abilities
})
}
return 'data' in response.data ? response.data.data : response.data
}
I can accomplish this same sort of thing by passing a 'model' into the axios config during the request:
API call:
const response = FooBar.api()
.get('/foobars', {
model: FooBar,
})
Then in dataTransformer, use it in response.config
:
dataTransformer: (response) => {
if ('model' in response.config && 'abilities' in response.data) {
response.config.model.commit((state) => state.abilities = response.data.abilities)
}
return 'data' in response.data ? response.data.data : response.data
}
However it seems reasonable to me that the plugin would pass in the model and make this cleaner.
Metadata
Metadata
Assignees
Labels
No labels