ember-data-copyable icon indicating copy to clipboard operation
ember-data-copyable copied to clipboard

fragment error

Open basz opened this issue 8 years ago • 2 comments

Hi,

can ember-data-copyable work with fragments? As soon as I make a fragment copyable the base model will not copy anymore Fragment.extend(Copyable.

Assertion Failed: You can only assign null, an object literal or a 'dossier/consumer' fragment instance to this property"

property is 'consumer'. and value is an 'instance' error comes from here : https://github.com/lytics/ember-data-model-fragments/blob/master/addon/attributes.js#L118

adding console.log(value) reveals two passing calls, and the last one fails, which looks different to me.

[Log] Class {__ember1513363568481: "ember1394", store: Class, _internalModel: InternalModel, currentState: Object, …} (vendor.js, line 128420)
[Log] Class {__ember1513363568481: "ember1395", store: Class, _internalModel: InternalModel, currentState: Object, …} (vendor.js, line 128420)
[Log] Class {__ember1513363568481: null, fn: function, args: [false], context: Class, owner: Class, …} (vendor.js, line 128420)
export default Model.extend(Copyable, Validations, {
  dossierNumber: attr('string'),
  openedDate: attr('date', { defaultValue: () => new Date() }),
  owningCustomerId: attr('string'),
  owningPracticeId: attr('string'),

  consumer: fragment('dossier/consumer', { defaultValue: {} }),
});

export default Fragment.extend(Copyable, Validations, {
  address: fragment('fragment/geography/address', { defaultValue: {} }),
  birthday: attr('date'),
  email: attr('string'),
  name: fragment('fragment/person/name/personname', { defaultValue: {} }),
  phone: attr('string'),
  sex: attr('string'),
});

basz avatar Dec 15 '17 18:12 basz

I think the only blocking issue that I know of are the transforms lookup (#5).

@mpirio might be of more help here.

offirgolan avatar Dec 30 '17 00:12 offirgolan

Hello, and Happy New Year :)

ember-data-copyable works with fragments. Fragment extends Ember.Copyable (see fragment.js#L70) and ember-data-copyable use copy method (see mixins/copyable.jsL146).

You do not need to extends Copyable when you make a new Fragment :

export default Fragment.extend(Validations, {
  address: fragment('fragment/geography/address', { defaultValue: {} }),
  birthday: attr('date'),
  email: attr('string'),
  name: fragment('fragment/person/name/personname', { defaultValue: {} }),
  phone: attr('string'),
  sex: attr('string'),
});

If you need custom copy, redefine copy method like this :

export default Fragment.extend(Validations, {
  address: fragment('fragment/geography/address', { defaultValue: {} }),
  birthday: attr('date'),
  email: attr('string'),
  name: fragment('fragment/person/name/personname', { defaultValue: {} }),
  phone: attr('string'),
  sex: attr('string'),

  copy(deep) {
    // your custom copy
  }
});

see https://emberjs.com/api/ember/2.18/classes/Ember.Copyable and https://github.com/lytics/ember-data-model-fragments/blob/master/addon/fragment.js#L91

mpirio avatar Jan 03 '18 16:01 mpirio