ES6 Compatibility
epreston opened this issue · 6 comments
Current implementation modifies the global "pc" variable to store its data. In the more modern and performant builds of pc engine, this does not work.
The current implementation of spine needs to store data and make features available to every app instance that the global "pc" instance might create. It needs to persist it even when those app instances, scenes, or root nodes are destroyed. At the time, a clever and graceful solution was to tuck things neatly into the "pc" variable to make sure its available no matter what happens.
While the chances for conflict are low, modern language features have been introduced to solve conflicts between vendor libraries. Unfortunately, the current approach is what a conflicting vendor library would do. If the spine plugin implementation took a different approach to meet those goals, this issue goes away.
It seems a small refactor is required.
This issue was first raised on the engine project here:
playcanvas/engine#5399
An ES6 refactor has been created here:
https://github.com/epreston/refactor-spine
@kungfooman could you check out the refactor demo and provide some guidance ?
- src/index.js which just exports what we need, like in PC engine repo
- src/main.js looks like a full example, should be probably in something like /test/
- remove vite, make it standalone, using importmaps in /test/test.html
Yes, its a demo / dev rig so I can iterate quickly. I'll map it back to this repo.
Good ideas, thank you.
Yes, its a demo / dev rig so I can iterate quickly.
Right, I guess the quickest way to iterate is no build process, so it would play into our hands. But I realized that esotericsoftware/spine is one of these projects, which don't know how to ship an ESM project (lack of *.js
in import ... from ...
). So we can forget about that without investing extra effort to patch up their product :(
If you like "no build" process, you should open the linked demo and watch it instantly reflect changes on every save, live update the webpage, etc.. What you code is instantly compiled / displayed.