Conversation
addon/mixins/form-data-adapter.js
Outdated
There was a problem hiding this comment.
Could you please clarify, why do we need both the iteration over fields and passing the whole fields array to those functions from within the iterations? I.e. couldn't we do something like this.getFormKey(key, fields[key])
There was a problem hiding this comment.
As in .forEach() I would pass the collection you're iterating over, you could be depending of relationships among the whole data being serialized. Anyway, as I can not imagine a clear use case for this right now, I agree on passing only key, fields[key].
|
@lodr Thanks for the pull request! I like the idea of allowing customization, provided that the default isn't changed. Could you please give an example of how this customization would be used and add/fix the tests? |
|
Of course. Here is the example based on my own code: import ApplicationAdapter from './application-adapter';
import FormDataAdapterMixin from 'ember-cli-form-data/mixins/form-data-adapter';
var OriginAdapter = ApplicationAdapter.extend(FormDataAdapterMixin, {
getDataToTransform(data) {
return data;
},
getFormKey(key, data) {
return key;
},
getFormValue(key, data) {
return data[key];
}
});
export default OriginAdapter;As you can see, I avoid the JSON root so I'm returning the same data object and so, for the serialization I'm skipping the What do you think? |
|
@funtusov Tests in PhantomJS are failing on my side, not in this branch but in master as well. In Firefox they run smooth and the introduced changes did not break anything. Anyway, do you want me to add some tests for the customization capabilities? |
|
@lodr I'm sorry for the late reply! I like this customisation approach, if you're still interested, could you please fix the current tests for phantomjs and add tests for those 3 new methods. |
In a project I'm working on, we choose to not wrap server responses. FormData Adapter seems pretty good but it assumes a rooted serialization. This alternative implementation does the same but allows the developer for further customization of what to be serialized into form data and how this serialization must to be done. What do you think?
Thanks for the plugin anyway!