Minimising javascript-side code in a ports module

Just in case it slipped through your searches, this discussion had interesting examples of how to make retries automatically by chaining tasks in one unique command. It might help in your quest to reduce the amount of JS code, or it might be useless.