yysun / apprun

AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.
https://apprun.js.org
MIT License
1.18k stars 57 forks source link

How to handle file drop? #100

Closed jkleiser closed 4 years ago

jkleiser commented 4 years ago

I'm trying to implement a simple JSON file drop in my SPA. I have tried both the $ondrop="ondrop" and the $ondrop={ondrop} way, but the e.preventDefault() does not seem to have any effect as my JSON data just replaces my SPA component when I drop the file. Is there a simple fix for this?

// Hello World ($on)
const state = '';
const view = state => <>
  <h1 $ondrop={ondrop}>Hello {state}</h1>
  <input $oninput={oninput}/>
</>;
const oninput = (_, e) => e.target.value;
const ondrop = (_, e) => {
  e.preventDefault();
  return e.toString();
}
app.start(document.body, state, view);
jkleiser commented 4 years ago

It seems the fix was to include a $ondragover="nodrag" and do a e.preventDefault() in that handler as well.