Skip to content

Commit

Permalink
Merge pull request #2 from ReactTraining/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
saravntbe authored Jun 11, 2018
2 parents 4796571 + 861bcb7 commit b3a005d
Show file tree
Hide file tree
Showing 753 changed files with 19,789 additions and 183,308 deletions.
10 changes: 0 additions & 10 deletions .babelrc

This file was deleted.

12 changes: 0 additions & 12 deletions .editorconfig

This file was deleted.

1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

33 changes: 0 additions & 33 deletions .eslintrc

This file was deleted.

7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
subjects/index.html
subjects/**/lecture.html
subjects/**/exercise.html
subjects/**/solution.html
!subjects/**/backbone-todomvc/index.html
node_modules
yarn-error.log
public/**/*.html
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

119 changes: 60 additions & 59 deletions JavaScriptPrimer.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ Note: All of the syntax discussed here is actually part of the JavaScript spec,
JavaScript has always had `var`:

```js
var name = 'Ryan'
var name = "Michael";
```

`var` can be hard to manage especially because of it's "function scoping", so now we've got two other ways to define values that have "block scope":

```js
// var does not have block scope
var name = 'Ryan'
var name = "Michael";
if (true) {
var name = 'Michael'
name // 'Michael'
var name = "Bruce";
name; // 'Bruce'
}
name // 'Michael'
name; // 'Bruce'

// let has block scope
let name = 'Ryan'
let name = "Michael";
if (true) {
let name = 'Michael'
name // 'Michael'
let name = "Bruce";
name; // 'Bruce'
}
name // 'Ryan'
name; // 'Michael'

// const has block scope too
const name = 'Ryan'
const name = "Michael";
if (true) {
const name = 'Michael'
name // 'Michael'
const name = "Bruce";
name; // 'Bruce'
}
name // 'Ryan'
name; // 'Michael'

// let can be reassigned
let isOpen = true
isOpen = false
isOpen // false
let isOpen = true;
isOpen = false;
isOpen; // false

// const cannot be reassigned
const isOpen = true
isOpen = false // throws error
const isOpen = true;
isOpen = false; // throws error
```

We find block scope to make more sense to people and is generally more useful, therefore we don't use `var`.
Expand All @@ -56,17 +56,17 @@ In practice, nearly everything is `const`.
## String templates

```js
const something = 'ugly stuff'
const str = 'instead of ' + something + ' like this'
const something = "ugly stuff";
const str = "instead of " + something + " like this";

const something = 'lovely stuff'
const str = `you can do ${something} like this`
const something = "lovely stuff";
const str = `you can do ${something} like this`;

const str = `
also
multiline
is totally cool
`
`;
```

## Concise object methods
Expand All @@ -82,7 +82,7 @@ const obj = {
youCanDoThis() {
// do stuff
}
}
};
```

## Arrow functions
Expand All @@ -91,89 +91,90 @@ Arrow functions remove the context from a function, meaning the function has no

```js
const obj = {
url: '/api/stuff',
url: "/api/stuff",

fetch(users) {
users.forEach((user) => {
users.forEach(user => {
// `this` is the `this` from outside this function because
// there is no context inside an arrow function
getUser(`${this.url}/${user.id}`)
})
getUser(`${this.url}/${user.id}`);
});
}
}
};
```

Also, if the other side of an arrow function is an expression, it acts like an implicit return:

```js
const add = function(x, y) { return x + y }
const add = function(x, y) {
return x + y;
};

// becomes
const add = (x, y) => { return x + y }
const add = (x, y) => {
return x + y;
};

// which can be shorter with explicit expression return
const add = (x, y) => x + y

// if we want multiline, we can create an expression with ()
const add = (x, y) => (
x + y
)
const add = (x, y) => x + y;
```

## Arrays

We do a lot with arrays, here are a few methods we use often:

```js
const numbers = [ 1, 2, 3, 4, 5 ]
const numbers = [1, 2, 3, 4, 5];

// map converts an array to a new, transformed array
const doubled = numbers.map((number) => {
return number * 2
})
doubled // [ 2, 4, 6, 8, 10 ]
const doubled = numbers.map(number => {
return number * 2;
});
doubled; // [ 2, 4, 6, 8, 10 ]

// filter, return false to remove from an array
const lessThan3 = numbers.filter((n) => {
return n < 3
})
lessThan3 // [ 1, 2 ]
const lessThan3 = numbers.filter(n => {
return n < 3;
});
lessThan3; // [ 1, 2 ]

// remember, that can be super short
const lessThan3 = numbers.filter(n => n < 3)
const lessThan3 = numbers.filter(n => n < 3);
```

## Destructuring

```js
const obj = { x: 1, y: 2 }
const obj = { x: 1, y: 2 };

// instead of:
const x = obj.x
const y = obj.y
const x = obj.x;
const y = obj.y;

// we can "destructure" the values off
const { x, y } = obj
x // 1
y // 2
const { x, y } = obj;
x; // 1
y; // 2

// you can use this all over the place, like function parameters
function add({x, y}) { return x + y}
add({x: 3, y: 4}) // 7
function add({ x, y }) {
return x + y;
}
add({ x: 3, y: 4 }); // 7
```

## Modules

```js
// instead of cjs
var React = require('react')
var React = require("react");

// we use ES modules
import React from 'react'
import ReactDOM from 'react-dom'
import React from "react";
import ReactDOM from "react-dom";

// and with destructuring to boot!
import { render } from 'react-dom'
import { render } from "react-dom";
```

Our training material then uses [Webpack](https://webpack.github.io/), a module bundler, to graph the dependencies and create a build so that this works in browsers that don't yet support some of these features natively.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ This repo contains the course material for [React Training](https://reacttrainin
First, install [git](http://git-scm.com/downloads) and the latest stable version of [node](https://nodejs.org/). Then:

```sh
$ git clone https://github.com/ReactTraining/react-subjects.git
$ cd react-subjects
$ git clone https://github.com/ReactTraining/react-workshop.git
$ cd react-workshop
$ npm install
$ npm start
```

Then open your browser to [http://localhost:8080](http://localhost:8080). You should see a list of subjects.
Your web browser should open to [http://localhost:8080](http://localhost:8080)where you'll see a list of subjects.

**IMPORTANT:** Please read the [JavaScript Primer](https://github.com/ReactTraining/react-subjects/blob/master/JavaScriptPrimer.md) before attending the workshop. It's a refresher on some of the newer bits of JavaScript you'll want to be familiar with in order to get the most out of the experience.

### Troubleshooting

A few common problems:

- **You're having problems cloning the repository.** Some corporate networks block port 22, which git uses to communicate with GitHub over SSH. Instead of using SSH, clone the repo over HTTPS. Use the following command to tell git to always use `https` instead of `git`:
* **You're having problems cloning the repository.** Some corporate networks block port 22, which git uses to communicate with GitHub over SSH. Instead of using SSH, clone the repo over HTTPS. Use the following command to tell git to always use `https` instead of `git`:

```sh
$ git config --global url."https://".insteadOf git://
Expand All @@ -29,19 +29,19 @@ $ git config --global url."https://".insteadOf git://
insteadOf = git://
```

- **You're having trouble installing node.** We recommend using [nvm](https://github.com/creationix/nvm). nvm makes it really easy to use multiple versions of node on the same machine painlessly. After you install nvm, install the latest stable version of node with the following command:
* **You're having trouble installing node.** We recommend using [nvm](https://github.com/creationix/nvm). nvm makes it really easy to use multiple versions of node on the same machine painlessly. After you install nvm, install the latest stable version of node with the following command:

```sh
$ nvm use default stable
```

- **You don't have permissions to install stuff.** You might see an error like `EACCES` during the `npm install` step. If that's the case, it probably means that at some point you did an `sudo npm install` and installed some stuff with root permissions. To fix this, you need to forcefully remove all files that npm caches on your machine and re-install without sudo.
* **You don't have permissions to install stuff.** You might see an error like `EACCES` during the `npm install` step. If that's the case, it probably means that at some point you did an `sudo npm install` and installed some stuff with root permissions. To fix this, you need to forcefully remove all files that npm caches on your machine and re-install without sudo.

```sh
$ sudo rm -rf node_modules

# If you installed node with nvm (suggested):
$ sudo rm -rf ~/.npm
$ sudo rm -rf ~/.npm

# If you installed node with Homebrew:
$ sudo rm -rf /usr/local/lib/node_modules
Expand Down
Loading

0 comments on commit b3a005d

Please sign in to comment.