Skip to content
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

feat(core): Switch to Promises everywhere. Adopt Node v4 ES6 #648

Merged
merged 2 commits into from
Jan 27, 2017

Conversation

tmcw
Copy link
Member

@tmcw tmcw commented Dec 29, 2016

This is a big one: this would switch documentation.js from callbacks to Promises entirely, while also adopting ES6 template strings and arrow functions. I'm following this table for the features to use: only those available in Node v4.

This is a big one, so pinging @arv @jfirebaugh to weigh in. From my perspective right now, this feels really good and I'm going to continue working on it. Promises make a lot of sense for documentation.js's APIs, where the automatic error-passing works pretty well.

There's still more to do on this PR: I expect CI tests to fail.

TODO:

  • Figure out how we're going to handle options for both build & format steps. Right now that messes up some of the tests. Document the approach: running mergeOptions on all Node API endpoints
  • Figure out how to merge in default options from yargs
  • Document Promises more accurate re: @dignifiedquire's great suggestion
  • Fix html output project name regression
  • Realizing that the refactored config system now runs mergeOptions twice if you call build. Should this be nixed?: buildSync is no longer an API method.

@tmcw tmcw force-pushed the future-promises branch 4 times, most recently from e945617 to 62582d5 Compare December 30, 2016 03:25
@dignifiedquire
Copy link
Contributor

One note about documenting promise returns, if you use Promise<string> instead of just Promise it's much easier to understand and read in the docs.

Copy link
Contributor

@arv arv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promises and Node4 makes the code easier to reason about. I'm all for it.

I took a quick look at the changes and made some minor comments.

.usage('Usage:\n\n' +
'# generate markdown docs for index.js and files it references\n' +
'$0 build index.js -f md\n\n' +
.usage(`Usage:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You lost one newline here. Is that intentional?

.then(files => {
watcher.add(files.map(data =>
typeof data === 'string' ? data : data.file));
}, err => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General advice is to use then(a).catch(b) instead of then(a, b) since the former would catch errors in a too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 switched all the instances.

@@ -112,8 +110,7 @@ module.exports = function (comments) {
node.comments.length ? path.concat(node.comments[0]) : []);
}

for (var i = 0; i < node.comments.length; i++) {
var comment = node.comments[i];
for (var comment of node.comments) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR description didn't mention for-of? I'm fine with that too even though it is pretty slow in Node4

@@ -97,7 +97,7 @@ function extractIdentifiers(path) {
* @returns {undefined} has side-effects
* @private
*/
Identifier: function (path) {
Identifier: path => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or using method syntax? Identifier(path) {

"glob": "^7.0.0",
"globals-docs": "^2.3.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an engines field too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 updated, added engines.

@@ -13,16 +13,7 @@
"type": "text",
"value": "f"
}
],
"data": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did these change?

@tmcw tmcw force-pushed the future-promises branch 3 times, most recently from 970d1bb to c437326 Compare December 31, 2016 16:15
@tmcw
Copy link
Member Author

tmcw commented Dec 31, 2016

Well, I'm unplugging and getting a brain-break shortly, but took the next step: using Flow to enforce types. That might look like just 'diving in', but I really think it is a winning move for the long-term success of documentation.js - it turns a lot of implicit types, like 'a comment' and 'a tag' into concrete types that we can enforce.

I'm using the Flow comment syntax, so, at the added cost of 4 extra chars per annotation, it spares us the need to transpile or remove type annotations.

@tmcw tmcw force-pushed the future-promises branch 4 times, most recently from 131628e to e1fc69d Compare January 10, 2017 03:33
Big changes:

* Uses template strings where appropriate
* Config and argument parsing is unified and there is no such thing
  as formatterOptions anymore. All user-passed options go through
  mergeConfig.

More changes:

* Remove buildSync command
* feat(inference): Partially implement object shorthand support
* Refs #649
* Use Flow annotations to  enforce types
* Keep flow but switch to comment syntax
* Clarify types
* More flow improvements
* Turn server into class
* LinkerStack becomes class too
* Fix comment description type
* Run flow on lint
* Many more flow fixes
* More intense flow refactoring
* Simplify inference steps
* Update inference tests, flow errors down to 1
* Continue refining types
* Fix more flow issues
* Use 'use strict' everywhere
* Make 'ast' property configurable
* Fix many tests
* Fix more tests
* Fix more tests
* Fix augments
* Test Markdown meta support
* Improve test coverage
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.2%) to 97.766% when pulling 497ab25 on future-promises into ec03e0b on master.

@tmcw
Copy link
Member Author

tmcw commented Jan 27, 2017

I'm going to accept the -1.2% coverage increase and merge this, so that we can iterate on this in master.

@tmcw tmcw merged commit 631c692 into master Jan 27, 2017
@tmcw tmcw deleted the future-promises branch January 27, 2017 21:14
@arv
Copy link
Contributor

arv commented Jan 28, 2017

This is epic. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants