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

Add Async Event Support #921

Merged
merged 7 commits into from
May 14, 2013
Merged

Add Async Event Support #921

merged 7 commits into from
May 14, 2013

Conversation

SlexAxton
Copy link
Member

Sorry I'm a bad citizen and also have a bunch of metadata changes in this (I work on planes a lot). If you scroll to the bottom of the diff, it's the new stuff. Seems to work in my testing, though we could probably add some formal tests for it. Async stuff is always a joy to test, but it shouldn't be too bad.

Docs for it are in the readme.

Currently I have support for this working for sync and async tests, but I think we should only document async tests, and leave in sync because it's not much code and people will accidentally do it, and if tests ever change, etc etc.

/cc @stucoxmedia @paulirish

@stucox
Copy link
Member

stucox commented May 6, 2013

Looks good.

Except JSHint doesn't like this (function in a loop)...

    for (i = 0; i < cbs.length; i++) {
      cb = cbs[i];
      // Force async
      setTimeout(function() {
        cb(res);
      },0);
    }

Not sure what we can do about that though – could swap it round so the loop's in a single call to the timeout function, but then all the callbacks would be synchronous with each other, which probably isn't ideal.

I agree the documentation should focus on async tests, but I don't think we should categorically say it's not supported for sync tests... maybe just don't mention sync at all, or say something like:

If you call Modernizr.on() for synchronous tests the callback will be invoked on the next tick, however we recommend handling synchronous tests synchronously where possible for speed and consistency.

An extra thought: how about renaming src/addTest to src/resolveAsyncTest or similar, to avoid confusion with the (synchronous) Modernizr.addTest?

@SlexAxton
Copy link
Member Author

JSHint doesn't like this (function in a loop)

I say we just add the exception comment :D

I don't think we should categorically say it's not supported

Right. Just undocumented. The note is good too.

An extra thought: how about renaming src/addTest to src/resolveAsyncTest

We have a lot of docs on adding your own test with addTest - perhaps we should expose it as an alias? I agree that it's confusing, but in the past it's the only mechanism people had for adding tests.

@ryanseddon
Copy link
Member

Testing wise I think we should include sinon.js so we can mock setTimeout and spy on the on method. Makes async testing less stabby.

@stucox
Copy link
Member

stucox commented May 7, 2013

We have a lot of docs on adding your own test with addTest - perhaps we should expose it as an alias? I agree that it's confusing, but in the past it's the only mechanism people had for adding tests.

Yeah I think we want to keep the external API the same. I reckon keep it as it is, but I'll stick some thoughts in another ticket for us to mull over for a later release.

@SlexAxton
Copy link
Member Author

Fixed the jshint error. Gonna pull this in since the whole repo is pretty much in dev mode. I think this works though, either way.

SlexAxton added a commit that referenced this pull request May 14, 2013
@SlexAxton SlexAxton merged commit 842f096 into Modernizr:master May 14, 2013
patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this pull request Feb 22, 2015
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

Successfully merging this pull request may close these issues.

3 participants