gabrieldoty / simplify-scorm

Scorm 1.2 Javascript API
MIT License
230 stars 77 forks source link

Change the way of bringing the API back to its original state #26

Closed xob closed 4 years ago

xob commented 4 years ago

I have discovered that the replaceWithAnotherScormAPI method is flawed. When an SCO keeps a pointer to the original API, after using this method a few times, something goes wrong. Hard to say what exactly, but it has to do with pointers not changing correctly. The SCO then starts writing to an old API that doesn't exist anymore, still triggers events, but then if you read from window.API, you get an empty dataset.

I have changed the approach completely. No more messing about with pointers. Instead, I go for a simple resetting of the default values, and replace the CMI object with a new one.

It's now a lot simpler to reset the API (one method to call instead of 3), and all the pointers follow correctly even if the SCO keeps a pointer to the initial API.

With this change, I suggest labelling the release as version 2.0.0, since there are breaking changes here. I also added a changelog, to start documenting the changes in the API.

xob commented 4 years ago

I recommend waiting before merging this Pull Request. While I have tested the code locally (and it works like a charm!), it hasn't gone through QA and has not yet been validated to be viable in a production environment.

I will update when that has been done. It should be a few weeks at most.