brainfoolong / form-data-json

A zero dependency, cross browser library to easily get or set/manipulate form input values as/from a json object.
https://brainfoolong.github.io/form-data-json
MIT License
60 stars 10 forks source link

Wouldn't it be nicer if toJSON returns promise #34

Closed yahyaerturan closed 1 year ago

yahyaerturan commented 1 year ago

When converting form it could be take time to convert file fields. I think it would be better if toJson returns a promise so we can be sure that it worked 100% as we use it with toJson().then()

brainfoolong commented 1 year ago

Hi. fromJson/toJson are synchronous. There is no need to await that. It is guaranteed, the moment the function returns something, that is has done all the work already.

There is only one "async"-like behaviour, the callback parameter when you have file fields as well.

Promises does not bring any useful performance boost here. I have tested it with 1000 fields in one form, no problem.

Also, changing the behaviour of an existing function in such way will break it for everyone else.

So, all in all, no feature the will be implemented here.

By the way, if you encounter any performance problem when you use this, you can always wrap it yourself into a promise handler. It will however still stall the browser for the processing time, as promises run still on the main thread of the JS engine.

Greetz