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

Add new section on scoping JS code #13041

Merged
merged 18 commits into from
Jan 9, 2019
Merged

Add new section on scoping JS code #13041

merged 18 commits into from
Jan 9, 2019

Conversation

oandregal
Copy link
Member

This PR has been created as a response to this comment by Marcus.

@oandregal oandregal self-assigned this Dec 20, 2018
@oandregal oandregal added this to the Documentation & Handbook milestone Dec 20, 2018
@oandregal oandregal added the [Type] Developer Documentation Documentation for developers label Dec 20, 2018
Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

The documentation looks clear and good to me. Maybe we can link to some external document if the reader wants more information on this subject.

I left some minor grammar nitpicks, I'm not totally sure if all my suggestions are correct as English is not my main language.

@oandregal
Copy link
Member Author

Thanks for copy-writing @jorgefilipecosta ! ❤️ Your comments were addressed.

Copy link
Contributor

@chrisvanpatten chrisvanpatten left a comment

Choose a reason for hiding this comment

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

Overall, I think this is excellent and an invaluable resource. (I even learned a thing or two!)

I tried to suggest some edits that simplify the overall tone a bit, and try to be a bit kinder to less-skilled developers. My hope is that these edits don't take away from the technical nature of the doc while still making it a little easier to understand if you're not too tech-savvy.

chrisvanpatten and others added 14 commits December 21, 2018 10:02
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
@oandregal
Copy link
Member Author

@jorgefilipecosta @chrisvanpatten I wasn't too fond of the original example, so I've rewritten it a bit. I've also merged Chris suggestions, which make the text a lot easier to follow (thanks!).

Let me know what you think.

Copy link
Contributor

@chrisvanpatten chrisvanpatten left a comment

Choose a reason for hiding this comment

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

Two tiny tweaks but I'll approve so we can merge quickly. Really nicely done on this, and the improvements with the example are great too — they make it a lot clearer!

chrisvanpatten and others added 2 commits January 2, 2019 09:53
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md

Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
@oandregal oandregal merged commit 36b1758 into master Jan 9, 2019
@oandregal oandregal deleted the update/js-tutorial branch January 9, 2019 17:18
oandregal added a commit that referenced this pull request Jan 9, 2019
The page is published in the handbook and the navigation menu,
but the contents are void.

Reverting while figuring out what happened.

Notice the _historically_.

JavaScript has evolved quite a bit since its creation. As of 2015, the language supports modules, also known as _ES6 modules_, that introduce separate scope per file: a global variable in `first.js` wouldn't be exposed to `second.js`. This feature is already [supported by modern browsers](https://caniuse.com/#feat=es6-module), but not all of them do. If your code needs to run in browsers that don't support modules, your last resort is using IIFEs.
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to surface that it's not needed for ES6 very early in the file for more clarity?

Copy link
Member Author

Choose a reason for hiding this comment

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

My intent was making this as free as jargon as possible as to make it more palatable to people not exposed to modern JavaScript just yet, that's why I only hinted at ES6 by the end of the file.

One way I think this tutorial could be expanded is by adding a section that includes a minimum viable mechanism to compile from ES6 to ES5 (including JSX). I was tempted to adapt my own dumb webpack explanation for the handbook. Upon sleeping on it, I think that a better use of everyone's time (the writer and the reader) will be to walk the reader through a minimal setup instead - that way we give developers an easy and practical way to get started and avoid the analysis paralysis.

Copy link
Contributor

Choose a reason for hiding this comment

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

A separate tutorial for build setup would be good, but we should probably wait for @wordpress/scripts improvements first and use it instead of using the tools directly cc @gziolo. I was more thinking of a random person arriving into this tutorial. They might already use ES6. So just a small note at the beginning could be useful IMO.

Copy link
Member

@gziolo gziolo Jan 21, 2019

Choose a reason for hiding this comment

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

Yes, I think we will need to add a tutorial about using wp-scripts in your project. There are three things that need happen before we can start promoting it:

@nosolosw would you like to work together on such tutorial?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd love to! Ping me in any PR that lacks a reviewer and I'll be there. When pieces are in place, I can also pair to write the tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants