-
Notifications
You must be signed in to change notification settings - Fork 23
Improving customization #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
addon/mixins/form-data-adapter.js
Outdated
| if (typeof fields[key] !== 'undefined') { | ||
| formData.append( | ||
| this.getFormKey(key, fields), | ||
| this.getFormValue(key, fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!