Echo JS 0.11.0

<~>

tquetano-r7 2957 days ago. link 1 point
Everything is promise-based (they aren't callbacks), but there are optional hooks to allow the developer to have another way to do accomplish their goals. What you describe is a perfectly logical way to process, but not the only way, and this gives more options to the developer.

It's a valid point about the one-shot function example ... I wrote the partial application setup because of the AJAX use specifically, but its far from the only use-case. I just released 1.1.0 that has a convenience function to satisfy just that:

import savery from 'savery';

savery.save(data, filename, options);

Another valid point about the abort function, and the problem was centered around the creation of the file vs the actual saving mechanism being coupled. As such, I have abstracted out the blob creation into a separate step in the chain, so the abort function has until the actual download trigger to prevent the save from operating.

Couple other things...

The return from either .save() call is a Promise of the saving lifecycle, so the .then() / catch you are looking for is already available. I've updated the documentation to reflect this.

I don't really know what to say about the "enterprisey" comment ... I'm sorry you don't like my code style? The small dedicated functions are for testability, and are just kind of a (I consider good) habit borne out of functional programming as a whole.

Anyways, appreciate the feedback, this is obviously in its infancy and any aide in its progress is welcome.
bfred.it 2956 days ago. link 1 point
Even if you invoke them in a Promise, they're still callbacks because you expect them as arguments.

My argument is that they should not be there at all since the native .then() covers all the cases. Now you have onEndSave/onAfterSave/onError/then/catch instead of just then/catch.

Also the onBeforeSave/onStartSave callbacks are one step away from adding onBeforeStartSave, onAfterStartSave, onBeforeAfterStartSave. Why do you have two callbacks for the same event?

Do you see the problem this approach? Your API is unnecessarily wide and that makes it harder for everybody involved: harder for you to cover all the possible events and harder for the next developer to make sense of all the possible+identical ways to do one thing.
bfred.it 2958 days ago. link 1 point
Way too many callbacks.

This should be a one-shot function like https://github.com/rndme/download that saves the file on the spot. Its post-callbacks should just be set as .then(done, errored), not passed as an option. Its before-callbacks should not be callbacks, but just functions that the user calls before `save()`

The whole thing is a bit enterprisey, including shortcut functions that are only used once, that let you write

createBlob(data, type);

instead of 

new window.Blob([data], {type});

Also .abort() doesn't really stop anything since onSave is essentially called in the frame and it doesn't abort the only asynchonous function: `saveWithFileReader`