Model data hooks

Hi Chaps, Is there any hooks for ‘model data state’ (afterSerialize) ? I know that we have Adapters and Serializers however I couldn’t find any hooks in docs. I am not able to use afterModel hook as this is only for ‘plain’ model. I’m using JSONAPI

Much appreciate for any help.

Thanks in advance

Regards Matt K.

What is your usecase? There are hooks in the route and component. For before rendering and after rendering.

I have 7 models where the main model is visitor and the rest models are used on specific situations like on click → get data for news model.

I prefer to load only visitor model, load css, components, wait for rendering and after that load data for specific model.

This specific data needs to be formatted and set as default questions to visitor.task(which is relationship to model task).answers (attribute for task).

Case: Clicking on task loading data which needs to be formated and save to attribute answers in model task and task have relationship to visitor. There can be more then 1 task.

If that make sense

Hi Kimek,

I’m not too clear on the requirements. But maybe you can load the data upfront and use logic in the templates to render the data depending on the logic.

//template
{{#if someConditionInController}}
  {{formatted-data-component someData=passedFromController}}
{{else}}
  {{some-other-format-data-component someData=passedFromController}}
{{/if}}

//component

export default Ember.component.extend({

  someData: ''

  formatData(){
    //let changedData = {};
    this.get('someData', changedData);
  }
})

Best, Elton

1 Like

Hi @l_tonz,

This sounds pretty good and it will work.

I’ve never though to use component as a ‘transformer’.

Thanks a lot !

Have a great day/night :wink:

1 Like