-
-
Notifications
You must be signed in to change notification settings - Fork 361
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
Remove Q Dependency #456
Remove Q Dependency #456
Conversation
Pull Request Test Coverage Report for Build 709
💛 - Coveralls |
I'll look into the code coverage over the next couple days as I find some time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all. AMAZING job!! I think you touched almost every line in this package. If only Git worked better and only showed the CHANGES it would have been a lot easier to review haha.
A lot of my comments are duplicates of ones I made previously. I tend to do that so it's easy to go back later and ensure that it was fixed in all the spots. So that is the purpose for me making so many notes.
I did have some major questions about high level things that we are doing in this PR. But a lot of those comments are duplicates of the first one.
There is also one comment I made with more detail that references one higher up. So it'd probably be a good idea to read through all the comments before making any changes.
HUGE thank you for this! 🎉 🎆 👏 🥇
lib/Model.js
Outdated
if(options.overwrite === null || options.overwrite === undefined) { | ||
options.overwrite = true; | ||
} | ||
if(next){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this. Why not create a helper function to use throughout the codebase? For example.
function promisify(promise, cb) {
promise.then(result => { cb(null, result); }, err => { next(err); });
return promise;
}
Then instead of this if
statement. We can just set the promise to a variable instead of returning it. Then do something like:
return promisify(promise, next);
That way we don't have to write the then
logic and all of that over and over.
You might have to play with that code. Probably do need a if
statement within that function I created to ensure that cb
exists. Not sure if the naming works and everything like that. So might need to play with it quite a bit.
With the current implementation I think someone trying to combine a callback with a promise would fail. So something like:
const item = Model.get("myitem", function(err, result) {
console.log(result);
});
I think in that case item
is undefined with your changes. But I think in the current version item
would exist.
I would almost consider that a breaking change. I have no idea how people are using Dynamoose, and although I wouldn't recommend that, I can't be positive that people aren't writing code like that.
I think my suggestion above would address that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is something I definitely struggled with, and would be up for going a different direction.
If we return a promise and the User doesn't catch it, Node will throw an unhandled promise rejection. Q promises don't dispatch the same node event, so they just fail silently. So we can return the promise, but if they are only using a callback Node will write to std err, which hopefully would never break anything, but would at least likely raise a few eyebrows to whether something changed. I feel like failing silently definitely isn't the way to go though. If you have any ideas for how you want to handle it, let me know!
Definitely up for abstracting it with the above though. I'll try to implement the above. Unfortunately the way some functions dynamically determine if a param is a config or a callback makes it pretty difficult to do the abstraction outside the function. Would definitely make the code cleaner if support was at least dropped for passing in a cb if omitting options, but that would definitely be a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking on the above, is the plan for the above to continue to support callbacks, or eventually move to entirely promises? Would it make sense to start deprecating certain things like callbacks, or at least passing callbacks in place of options? Might make any eventual breaking changes to the API a lot easier, but I don't know if that's the eventual plan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using my first example above. Wouldn't we be catching the error there tho? Isn't the only difference the fact that we are returning the promise and abstracting it a bit more?
As of right now there is no plan to deprecate callbacks. It's something I'd be open to discussing. But as of right now there has been no discussion regarding it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be abstracted into it's own file/method now. I've called it linkPromiseToCallback
, and put it in a new helpers.js
file. Not in love with either though, so if you want me to change the name/location let me know.
}; | ||
|
||
Table.prototype.update = function (next) { | ||
// let ddb = this.base.ddb(); | ||
// ddb.updateTable(); | ||
const deferred = Q.defer(); | ||
deferred.reject(new Error('TODO')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder who wrote this code, and what the purpose of this is. Before this gets merged in, I should probably figure out how to look at the blame, to figure out when this was written to track it down and figure out how to implement it.
If you are able to do that quickly that'd be awesome. But I think it needs to be done before this gets merged in, or else I think it'd be a lot harder afterwards.
@@ -50,8 +50,7 @@ | |||
"debug": "^2.6.8", | |||
"deep-equal": "^1.0.1", | |||
"hooks": "0.3.2", | |||
"object-path": "^0.11.4", | |||
"q": "^1.5.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YAY 🎉
@Aedalus One other question. Do you think we should add tests for this? I mentioned that we shouldn't change the tests in this PR. But I'd totally be in for adding tests. |
@Aedalus And I just saw your comment about code coverage. It's been doing that for a while now. I feel like it's some type of glitch. With all the changes you made, and no changes to the tests, losing |
Looks like test failed due to timeout. Restarting. |
@Aedalus If you could do me a favor and mark the comments I made as resolved once you finish them I'd really appreciate it. Just so we can keep track of what changes still need to be addressed before merging. I marked a few as complete based on the last commit you made. |
@Aedalus Looks like this build is failing for some reason. Wanna take a look at that at some point? |
@Aedalus Were you able to make any progress on this? |
@fishcharlie I've made some, work's just been a little crazy. Hoping to finish it up by this weekend so the PR isn't just rotting here. |
Co-Authored-By: Aedalus <TheAlexanderHiggins@gmail.com>
Co-Authored-By: Aedalus <TheAlexanderHiggins@gmail.com>
@fishcharlie Newest changes are in. I tried to follow your suggestion with removing the |
@@ -276,75 +276,78 @@ function validKeyValue(value) { | |||
return value !== undefined && value !== null && value !== ''; | |||
} | |||
|
|||
Model.prototype.put = function(options, next) { | |||
Model.prototype.put = function(options = {}, next) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff of this entire section looks really different. For example, the if(typeof options === 'function') {
is within the switch statement. I think the goal of this PR should be focused entirely on removing the Q dependency, and not changing any logic at all. The goal should be to create the least amount of changes possible to get this working.
These changes look ok, but I think they should be made in a separate PR from this.
RequestItems: {} | ||
}; | ||
return new Promise((resolve, reject) => { | ||
debug('BatchGet %j', keys); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still hasn't been addressed
|
||
module.exports = { | ||
linkPromiseToCallback, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a new line at the end of the file
@@ -0,0 +1,11 @@ | |||
function linkPromiseToCallback(promise, cb) { | |||
// If a callback exists, call it | |||
if(cb) promise.then(result => { cb(null, result); }, err => { cb(err); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we separate this out into new lines?
I'm also concerned about this. We need to make sure that it falls through when you chain stuff to this promise. Have you tested promise support manually with this?
Another issue I just realized. https://github.com/fishcharlie/dynamoose/blob/pluginsupport-async/lib/Scan.js#L207 That line. We are passing |
@Aedalus Any progress on this? 😃 |
Closing this due to no recent activity. If this is still a problem or you have questions please feel free to comment again and we can try to help further. |
Summary:
This PR removes the dependency on Q while maintaining the current promise and callback based API.
Code sample:
Schema
Model
General
GitHub linked issue: #216
Closes #216
Type (select 1):
Is this a breaking change? (select 1):
Is this ready to be merged into Dynamoose? (select 1):
Are all the tests currently passing on this PR? (select 1):
Other:
npm test
from the root of the project directory to ensure all tests continue to pass