Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Only use one thunking method. #89

Closed
wants to merge 1 commit into from

3 participants

Stephen Belanger jongleberry TJ Holowaychuk
Stephen Belanger

The previous code would run objectToThunk on EVERY object,
even if it was also a promise, thunk, generator or array.

Stephen Belanger Qard Only use one thunking method.
The previous code would run objectToThunk on EVERY object,
even if it was also a promise, thunk, generator or array.
4928480
jongleberry
Collaborator

hmmm don't know if the tests pass @visionmedia can you enable travis?

TJ Holowaychuk
Owner
tj commented

enabled, but nope this breaks tests

TJ Holowaychuk
Owner
tj commented

also we should have a regression test

TJ Holowaychuk tj closed this in d481549
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 18, 2014
  1. Stephen Belanger

    Only use one thunking method.

    Qard authored
    The previous code would run objectToThunk on EVERY object,
    even if it was also a promise, thunk, generator or array.
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 7 deletions.
  1. +21 −7 index.js
28 index.js
View
@@ -114,13 +114,27 @@ function co(fn) {
*/
function toThunk(obj, ctx) {
- var fn = obj;
- if (Array.isArray(obj)) fn = objectToThunk.call(ctx, obj);
- if ('[object Object]' == toString.call(obj)) fn = objectToThunk.call(ctx, obj);
- if (isGeneratorFunction(obj)) obj = obj.call(ctx);
- if (isGenerator(obj)) fn = co(obj);
- if (isPromise(obj)) fn = promiseToThunk(obj);
- return fn;
+ if (isGeneratorFunction(obj)) {
+ return obj.call(ctx);
+ }
+
+ if (isGenerator(obj)) {
+ return co(obj);
+ }
+
+ if (isPromise(obj)) {
+ return promiseToThunk(obj);
+ }
+
+ if (Array.isArray(obj)) {
+ return arrayToThunk.call(ctx, obj);
+ }
+
+ if ('[object Object]' == toString.call(obj)) {
+ return objectToThunk.call(ctx, obj);
+ }
+
+ return obj;
}
/**
Something went wrong with that request. Please try again.