dorukeker / gyronorm.js

JavaScript project for accessing and normalizing the accelerometer and gyroscope data on mobile devices
MIT License
640 stars 65 forks source link

[WIP/Do not merge] Internals refactor and add tests #12

Closed mordack closed 6 years ago

mordack commented 8 years ago

This PR refactors a lot of the internals, and adds tests for most of the public API. The tests are all unit tests which mock the calls to FillTilt.

Most notable internal change is that each GyroNorm instance has it's own private variables, instead of having those private variables shared between every instance. Those private instance variables are now initialized in the GyroNorm constructor function instead of the init function. This is a breaking change if you have more than one GyroNorm instance, and assume the data returned in every snapshot callback is the same everywhere (because this is what it used to do, every instance just overwrote the shared state).

Most other refactorings split out functions into smaller functions to improve testability and make the code more readable.

I haven't been able to/don't know how to actually test this on my mobile device, so I haven't verified if everything is still working 😇, will update this PR when breakage occurs.