glkote
glkote copied to clipboard
First pass at ES Modules
First pass at moving to using ES Modules etc (#37). I have converted all the files, but at this stage only tested glkote.js and dialog.js as those are all that the demo files use.
Note that file: URLs can't load ES Modules, so I've provided a mini python script to run a web server. Probably could have done it in Node now that I think about it, but it's what I was already using.
ES Modules require strict mode, which GlkOte really was not at all prepared for. So I've started linting the files using ESLint. At this stage only for errors and things regarded as significant anti-patterns, in the future we could turn on some style rules if you want. This is what the bulk of the changes are for, there were a lot of undeclared variables or redeclared variable errors.
Moving forward:
-
I would like to switch to using ES Classes. They're supported everywhere except IE 11 now, so I think they're a safe choice. Using classes would more naturally match the decoupled organisation of the modules where instead of relying on things being on
window
we pass in what each module needs when it's instantiated. -
My plan is to use Rollup and Terser to provide a bundled file for Quixe/Parchment/IFComp/Lectrote etc. The question is where to do the bundling. It could happen either here or upstream. I'm not sure which would be best. Once we do that, then I'll test it in Quixe etc.