mardi 19 mars 2019

How to handle multiple ember models for same resource

I have a model user in app/models/user.js with the following:

import attr from 'ember-data/attr';
import Model from 'ember-data/model';

export default Model.extend({
  email:        attr('string'),
  username:     attr('string'),
  firstName:    attr('string'),
  lastName:     attr('string'),
  currency:     attr('string'),
  locale:       attr('string'),
  avatar:       attr('string')
});

And I want to update its attributes in different routes:

In http://localhost:4200/account/profile I want to update just:

  • firstName
  • lastName
  • avatar
  • username

In http://localhost:4200/account/preferences I want to update just:

  • locale
  • currency

I'm using ember pod structure so I was thinking to create two models inside those routes with custom adapters and serializers to handle validations and serialize just the attributes that I want for each route.

- models
  - user.js
- pods
   - account
     - profile
       - adapter.js
       - controller.js
       - model.js
       - route.js
       - serializer.js
       - template.hbs
     - preferences
       - adapter.js
       - controller.js
       - model.js
       - route.js
       - serializer.js
       - template.hbs


But this solution has problems with data binding because I'm not updating the user model.

What would it be a good approach for doing this?




Aucun commentaire:

Enregistrer un commentaire