Skip to content

Commit 16ebf62

Browse files
committed
Merge pull request #7 from nodegit/fix-refactoring
Undo revert of refactored code
2 parents 23acd62 + 391fe9a commit 16ebf62

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

index.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,29 @@ function processExports(exports, test, cached, parentKeyName) {
3737
exports[keyName] = processExports(exports[keyName], test, cached, name);
3838
}
3939

40-
// Assign the new function in place.
41-
var wrapped = Promise.denodeify(exports);
42-
4340
// Find methods on the prototype, if there are any.
4441
if (Object.keys(exports.prototype).length) {
4542
processExports(exports.prototype, test, cached, name);
4643
}
4744

45+
// If a filter function exists, use this to determine if the function
46+
// is asynchronous.
47+
if (test) {
48+
// Pass the function itself, its keyName, and the parent keyName.
49+
if (!test(exports, exports.name || parentKeyName, parentKeyName)) {
50+
return exports;
51+
}
52+
}
53+
54+
// If the callback name exists as the last argument, consider it an
55+
// asynchronous function. Brittle? Fragile? Effective.
56+
else if (callbacks.indexOf(args(exports).slice(-1)[0]) === -1) {
57+
return exports;
58+
}
59+
60+
// Assign the new function in place.
61+
var wrapped = Promise.denodeify(exports);
62+
4863
// Attach the augmented prototype.
4964
wrapped.prototype = exports.prototype;
5065

@@ -57,35 +72,17 @@ function processExports(exports, test, cached, parentKeyName) {
5772
Object.keys(exports).map(function(keyName) {
5873
// Convert to values.
5974
return [keyName, exports[keyName]];
60-
}).filter(function(keyVal) {
75+
}).forEach(function(keyVal) {
6176
var keyName = keyVal[0];
6277
var value = keyVal[1];
6378

6479
// If an object is encountered, recursively traverse.
6580
if (typeof value === "object") {
6681
processExports(exports, test, cached, keyName + ".");
6782
}
68-
// Filter to functions with callbacks only.
69-
else if (typeof value === "function") {
70-
// If a filter function exists, use this to determine if the function
71-
// is asynchronous.
72-
if (test) {
73-
// Pass the function itself, its keyName, and the parent keyName.
74-
return test(value, keyName, parentKeyName);
75-
}
76-
77-
// If the callback name exists as the last argument, consider it an
78-
// asynchronous function. Brittle? Fragile? Effective.
79-
if (callbacks.indexOf(args(value).slice(-1)[0]) > -1) {
80-
return true;
81-
}
82-
}
83-
}).forEach(function(keyVal) {
84-
var keyName = keyVal[0];
85-
var func = keyVal[1];
8683

8784
// Wrap this function and reassign.
88-
exports[keyName] = processExports(func, test, cached, parentKeyName);
85+
exports[keyName] = processExports(value, test, cached, parentKeyName);
8986
});
9087

9188
return exports;

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ describe("Promisify", function() {
9898
a: function a() { arguments[0](); }
9999
};
100100

101-
promisify(Test, function(func, keyName, parentKeyName) {
102-
return func.name === "a";
101+
promisify(Test, function(func, keyName) {
102+
return keyName === "a";
103103
});
104104

105105
return new Test().a();

0 commit comments

Comments
 (0)