aurelia-files
aurelia-files copied to clipboard
Allow on-loaded.call binding feature request
If on-loaded.bind
is used, the callback does not have access to its view-model's this
. Using .call
fixes that:
file-reader-helper.js
onLoaded({file, contents: fileLoadedEvent.target.result});
consumer.html
<input type="file" files="on-loaded.call: fileLoadedCallback(file, contents);">
However, note that this forces your plugin code that calls the specified callback to pass an object instead of individual parameters, which will break existing .bind
usage.
I'm not sure if there is a way of telling which kind of binding the consuming element is using. If there is, you could call onLoaded
with individual arguments for .bind
and with an object with .call
. That way you could easily handle each type of binding.
Feel free to raise a PR as long as the examples work its all fine, although I would say that stuff like this can probably be solved by using the fat arrow for the VM method, i.e.
// myVM.js
this.fileLoadedHandler = (file, contents) => { ... }
// MyView.html
<input type="file" files="on-loaded.bind: fileLoadedHandler "/>`