Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop function to pause idle.js in certain occasion #2

Closed
gabrielstuff opened this issue Dec 18, 2016 · 11 comments
Closed

stop function to pause idle.js in certain occasion #2

gabrielstuff opened this issue Dec 18, 2016 · 11 comments

Comments

@gabrielstuff
Copy link
Member

No description provided.

@TheGauntt
Copy link

👍

Note that you can do:

var event = new CustomEvent("idle:stop", {});
window.dispatchEvent(event);

@gabrielstuff
Copy link
Member Author

Nice found. Indeed we already have it here.

window.addEventListener('idle:stop', function (event) {
So we can just add a function :

stop () {
  var event = new CustomEvent("idle:stop", {});
  window.dispatchEvent(event);
}

@TheGauntt
Copy link

TheGauntt commented Nov 25, 2017

Yep, but unfortunately that's broken. This PR fixes it: #5

@gabrielstuff
Copy link
Member Author

@himdel we have an issue with removing the eventlistener. I did not have time to fix it. Currently the examples does not pass. If you have time to check it. If not I will work on it later today.

@himdel
Copy link
Contributor

himdel commented Feb 6, 2019

@gabrielstuff Looking..

So far, looks like one of the issues is that example/vanilla/index.html is referencing ../dist instead if ../../dist...

And second issue.. somehow, the global object changed the name from idleJs to IdleJs.
(apparently in a77eece)

With those changes (#14), the vanilla example works,
and the webpack one fails on missing _idle, still looking :).

@himdel
Copy link
Contributor

himdel commented Feb 6, 2019

idle.stop() fails with

Idle.js:12 Uncaught ReferenceError: __idle is not defined
    at Idle.js:12
    at Array.forEach (<anonymous>)
    at bulkRemoveEventListener (Idle.js:11)
    at IdleJs.stop (Idle.js:91)
    at <anonymous>:1:6

even in the vanilla example, so the problem is in how we build dist/, not in the webpack example itself.

@himdel
Copy link
Contributor

himdel commented Feb 6, 2019

Oh! It's in the source .. comes from f7db055, the __idle function is really not defined in the other function, as functions defined inside another function are local to the scope of the parent function only.

(Also, it can't work because the function gets created separately for each event type, so the reference won't be the same:

> a = [1,2,3].map((i) => function() {})
[ [Function], [Function], [Function] ]
> a[0] === a[1]
false

> f = function() {}
[Function: f]
> f === f
true

)

@himdel
Copy link
Contributor

himdel commented Feb 6, 2019

Fixed in #17 :)

(And made a bunch more small PRs for things I noticed.)

@gabrielstuff
Copy link
Member Author

thank @himdel, now we have 1.1.2 https://github.com/soixantecircuits/idle-js/releases/tag/v1.1.2 which include all of your contribution.

@gabrielstuff
Copy link
Member Author

You can check out https://github.com/soixantecircuits/idle-vue/issues which depends on. For sure, you just gave a new breath to the project.

Thanks a lot!

@himdel
Copy link
Contributor

himdel commented Feb 8, 2019

Thanks @gabrielstuff , happy to hear that :). And thanks for making it easy :).

As for idle-vue, looks like most issues are either resolved now, or vue specific, or resolved except for the vue specific bits :),
so, I'm not sure I'll be able to help there much, Vue is the (only? :)) framework our app is currently not using :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants