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
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:
The data transformer in this case is global and applies to every model. So in the calling code I am using the static FooBar, but in the transformer itself I don't know which model was called as it's generic to every model.
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:
Now in the transformer:
I can accomplish this same sort of thing by passing a 'model' into the axios config during the request:
API call:
Then in dataTransformer, use it in
response.config
:However it seems reasonable to me that the plugin would pass in the model and make this cleaner.
The text was updated successfully, but these errors were encountered: