thefrontside / emberx-form

Form/field components for working with changesets
MIT License
3 stars 1 forks source link

Allow Changeset to be passed-in #30

Open flexyford opened 7 years ago

flexyford commented 7 years ago

Hey Frontside,

Love this addon and have been working to allow an array of changesets to be passed-in via positional params. This differs from the current format of passing in an Object, which will then be wrapped in a Changeset internally.

Usage:

{{#x-form changesets
   onCancel=(action restore)
   onSubmit=(action submit)
   onError=onError
   onSuccess=onSuccess as |form|
}}

The primary difference would be tracking form properties. In the example below, we map over changesets.

// x-form.js
changesets: [],
isInvalid: computed('changesets.@each.isInvalid', function() {
  return get(this, 'changesets').any(c => get(c, 'isInvalid'));
}),
isPristine: computed('changesets.@each.isPristine', function() {
  return get(this, 'changesets').every(c => get(c, 'isPristine'));
}),
isValid: computed.not('isInvalid'),
isDirty: computed.not('isPristine'),
validateChangesets(changesets) {
  return RSVP.all( changesets.map(c => c.validate()) );
},

Is there any interest to allow passing Changeset Objects into the addon? If so I think we could implement this enhancement without introducing breaking changes. Thanks 👋