shake.js icon indicating copy to clipboard operation
shake.js copied to clipboard

Simplify the API?

Open dandv opened this issue 9 years ago • 8 comments

The current flow for detecting a shake looks more complicated than it needs to be:

var myShakeEvent = new Shake({ ... senstivity options ... });
window.addEventListener('shake', shakeEventDidOccur, false);
window.removeEventListener('shake', shakeEventDidOccur, false);
myShakeEvent.stop();

@leecrossley's cordova-plugin-shake-detection has a minimally simple API:

shake.startWatch(shakeEventDidOccur, /* ... sensitivity options ... */);
shake.stopWatch();

Could the API be simplified?

dandv avatar Apr 17 '15 12:04 dandv

This is indeed on my road-map. I plan to remove the shake custom event, and simply allow folks to pass their callbacks on instantiation.

alexgibson avatar Apr 17 '15 13:04 alexgibson

Great to hear!

I could imagine a use case for having more Shake instances instead of a singleton (e.g. supporting light shakes vs. heavy shakes), but the shake event doesn't receive any parameters, so it couldn't distinguish how it was called anyway.

dandv avatar Apr 17 '15 13:04 dandv

Will the request full screen from the API work with the shake event ?

This isn't really related to this issue. Not quite sure I understand your question, but you can execute any code you want when the event occurs. Please see the readme for how to use the plugin.

alexgibson avatar Jun 11 '15 18:06 alexgibson

I tried the proximity api to execute fullscreen , it did not happen

What does that have to do with this plugin?

alexgibson avatar Jun 11 '15 19:06 alexgibson

As far as I understand that's a limitation of the full screen API, not this plugin. Shake is a custom event, so not necessarily the same as a native click.

Regardless, this has nothing to do with this issue. Please open a new issue if you would like to discuss this further.

alexgibson avatar Jun 11 '15 19:06 alexgibson

I'm sorry @abkhan25 but the comments about full-screen and whatnot are off-topic here.

@alexgibson: feel free to delete the clutter, including this comment of mine.

dandv avatar Jun 11 '15 21:06 dandv

I can here to propose a callback instead of custom event as you mentioned in second comment. I need to play a sound when user shakes, but it's not possible with a custom event. It requires a user interaction. Which I guess device motion is. So a callback should fix that.

JonWallsten avatar Jun 13 '16 11:06 JonWallsten

up up, this is important issue

avrebarra avatar Feb 07 '17 22:02 avrebarra