Permalink
Browse files

fix toThunk object check regression. Closes #89

  • Loading branch information...
1 parent e65c811 commit d481549e7e8ae695d4a2e182088bbfea32cd5fc9 @tj committed Feb 18, 2014
Showing with 25 additions and 7 deletions.
  1. +25 −7 index.js
View
@@ -114,13 +114,31 @@ 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 (Array.isArray(obj)) {
+ return objectToThunk.call(ctx, obj);
+ }
+
+ if (isGeneratorFunction(obj)) {
+ return co(obj.call(ctx));
+ }
+
+ if (isGenerator(obj)) {
+ return co(obj);
+ }
+
+ if (isPromise(obj)) {
+ return promiseToThunk(obj);
+ }
+
+ if ('function' == typeof obj) {
+ return obj;
+ }
+
+ if (obj && 'object' == typeof obj) {
+ return objectToThunk.call(ctx, obj);
+ }
+
+ return obj;
}
/**

0 comments on commit d481549

Please sign in to comment.