-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
MWS: Async rewrite #8888
base: multi-wiki-support
Are you sure you want to change the base?
MWS: Async rewrite #8888
Conversation
Confirmed: Arlen22 has already signed the Contributor License Agreement (see contributing.md) |
✅ Deploy Preview for tiddlywiki-previews ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Before I forget, this adds a NODE_DEV_PATH env variable which when set causes stack traces to print the actual file location instead of the tiddler name. This way you can just click on the line in the stack trace and it takes you directly to the file. |
It also allows startup and commander code to handle startups and commands that return promises while still maintaining backward compatibility. |
14c7c36
to
1ec60ed
Compare
IMO this one is interesting in general. Can we have this one as a separated PR, or is this PR needed for that feature? |
I think that's a "side effect" you wanted for a long time. -- "Sneaking in such functionality" does not work all too well, if this PR is rejected, the side effect is gone. So is it possible to have this one as a standard PR, with only one goal |
I don't remember ever wanting that in those particular scenarios. I've only ever needed it in relation to the file system loading where no callback option was possible. And if I was trying to be sneaky about it I wouldn't put it by itself in the third comment of the PR. But now my lack of sleep is clearly showing!
I wanted to make as few changes as possible to avoid cluttering up the git diffs and to make it easy to understand what would have to be changed to convert to async. In order to do that it was easier to add the async keyword to startup and command functions and then add a bit of code behind the scenes to handle it rather than invoking callback hell while attempting to demonstrate how simple async/await can be. It wouldn't be hard to convert the startups and commands to use the callback option that is already there. You basically just wrap the code in an async IIFE:
|
@pmario Sure. I've opened #8889 for that. Some further details are there. |
@@ -10,673 +10,678 @@ Validation is for the most part left to the caller | |||
|
|||
\*/ | |||
|
|||
(function() { | |||
(function () { |
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.
There is a prettyprinting problem here. We do use TAB 4 as indentation in TW.
And there is no space between function()
await this.engine.runStatements([` | ||
-- Users table | ||
CREATE TABLE IF NOT EXISTS users ( | ||
user_id INTEGER PRIMARY KEY AUTOINCREMENT, |
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.
Indentation is broken here. So it is not really readable anymore
}); | ||
return updateBags.lastInsertRowid; | ||
}; | ||
async createBag(bag_name, description, accesscontrol) { |
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.
no spaces between function parameters and TAB indentation
|
||
SqlTiddlerStore.prototype.removeEventListener = function(type,listener) { | ||
removeEventListener(type, listener) { |
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.
no spaces for params
@pmario, is there a style guide anywhere that I can refer to? Is there some kind of prettier spec or eslint rule that's supposed to be applied? I tried using eslint format, but the entire mws plugin is inconsistently formatted to begin with which just cluttered up the diff. II tried to do whatever caused the least amount of changes in the git diff so I tried to preserve the messed up formatting wherever possible. That being said, I didn't do as well with |
There is an |
Auto-formatting should be switched off. At the moment we still have the "function() wrapper" active. All the auto formatters mess up the indentation, because they do want to indent 1 level, that is not necessary. There is a consensus, that this wrapper function will go away, because it is redundant in 99.9% of the cases. But that's not done yet. |
It was kind of fun. This took me about 12 hours, not counting interruptions.
It's not much of a rewrite, more just converting every database call (and everything upstream of every database call) to async/await.
If you haven't used VSCode, you're definitely going to want to explore the code using it to fully appreciate the little improvements that typing can bring.
I'm still working out a few bugs surrounding the somewhat confusing authenticatedUser property. But I'm too tired and I need to get some sleep and take a fresh look at it later.