Skip to content

Commit 1e99e15

Browse files
committed
Lesson 10 Examples, Exercises, Activity starter
1 parent 82b4b91 commit 1e99e15

File tree

103 files changed

+4589
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+4589
-0
lines changed

Lesson10/.editorconfig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
# The JSON files contain newlines inconsistently
13+
[*.json]
14+
insert_final_newline = ignore
15+
16+
# Minified JavaScript files shouldn't be changed
17+
[**.min.js]
18+
indent_style = ignore
19+
insert_final_newline = ignore
20+
21+
# Makefiles always use tabs for indentation
22+
[Makefile]
23+
indent_style = tab
24+
25+
# Batch files use tabs for indentation
26+
[*.bat]
27+
indent_style = tab
28+
29+
[*.md]
30+
trim_trailing_whitespace = false
31+

Lesson10/.gitignore

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env
67+
.env.test
68+
69+
# parcel-bundler cache (https://parceljs.org/)
70+
.cache
71+
72+
# next.js build output
73+
.next
74+
75+
# nuxt.js build output
76+
.nuxt
77+
78+
# vuepress build output
79+
.vuepress/dist
80+
81+
# Serverless directories
82+
.serverless/
83+
84+
# FuseBox cache
85+
.fusebox/
86+
87+
# DynamoDB Local files
88+
.dynamodb/
89+
dist

Lesson10/01-first-class/.babelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
"@babel/preset-react"
4+
],
5+
"plugins": [
6+
[
7+
"transform-class-properties"
8+
]
9+
]
10+
}

Lesson10/01-first-class/.gitignore

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env
67+
.env.test
68+
69+
# parcel-bundler cache (https://parceljs.org/)
70+
.cache
71+
72+
# next.js build output
73+
.next
74+
75+
# nuxt.js build output
76+
.nuxt
77+
78+
# vuepress build output
79+
.vuepress/dist
80+
81+
# Serverless directories
82+
.serverless/
83+
84+
# FuseBox cache
85+
.fusebox/
86+
87+
# DynamoDB Local files
88+
.dynamodb/
89+
dist
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// A function can be assigned to a variable
2+
const fn = function run() {
3+
return 'Running...';
4+
};
5+
6+
// A function can be set as
7+
// a value in an Array
8+
const operations = [
9+
fn,
10+
function() {
11+
console.log('Regular functions work');
12+
},
13+
() => console.log('Arrows work too')
14+
];
15+
16+
// A function can be set as a
17+
// value in an object
18+
const Module = {
19+
// With ES6 shorthand property
20+
fn,
21+
method1() {},
22+
arrow: () => console.log('works too')
23+
};
24+
25+
console.assert(Module.fn() === 'Running...');
26+
27+
// A function can be passed as an argument
28+
function runner(fn) {
29+
return fn();
30+
}
31+
32+
console.assert(runner(fn) === 'Running...');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<div id="app"></div>
2+
<script src="./example-10-this-react-issues.js">
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Run with
2+
// npm run serve example-10-this-react-issues.html
3+
import React from 'react';
4+
import ReactDOM from 'react-dom';
5+
6+
class Child extends React.Component {
7+
render() {
8+
return <div>
9+
<p><button onClick={() => this.props.withInlineBind('inline-bind')}>inline bind</button></p>
10+
<p><button onClick={() => this.props.withConstructorBind('constructor-bind')}>constructor bind</button></p>
11+
<p><button onClick={() => this.props.withArrowProperty('arrow-property')}>arrow property</button></p>
12+
</div>;
13+
}
14+
}
15+
16+
class Parent extends React.Component {
17+
constructor() {
18+
super();
19+
20+
this.state = {
21+
display: 'default'
22+
};
23+
24+
this.withConstructorBind = this.withConstructorBind.bind(this);
25+
}
26+
27+
// check the render() function
28+
// for the .bind()
29+
withInlineBind(value) {
30+
this.setState({
31+
display: value
32+
})
33+
}
34+
35+
// check the constructor() function
36+
// for the .bind()
37+
withConstructorBind(value) {
38+
this.setState({
39+
display: value
40+
})
41+
}
42+
43+
// works as is but needs
44+
// an experimental JavaScript feature
45+
withArrowProperty = (value) => {
46+
this.setState({
47+
display: value
48+
})
49+
}
50+
51+
render() {
52+
return (
53+
<div>
54+
<p>{this.state.display}</p>
55+
<Child
56+
withInlineBind={this.withInlineBind.bind(this)}
57+
withConstructorBind={this.withConstructorBind}
58+
withArrowProperty={this.withArrowProperty}
59+
/>
60+
61+
</div>
62+
);
63+
}
64+
}
65+
66+
ReactDOM.render(<Parent />, document.querySelector('#app'));
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function getData(transport) {
2+
return transport('https://hello-world-micro.glitch.me').then(res => res.text())
3+
}
4+
5+
// in some server-side code
6+
const axios = require('axios');
7+
const axiosWithServerHeaders = axios.create({
8+
headers: { Authorization: 'Server-side allowed' }
9+
});
10+
getData(axiosWithServerHeaders);
11+
12+
// in some client-side code
13+
import axios from 'axios';
14+
const axiosWithCookies = axios.create({
15+
withCredentials: true
16+
})
17+
getData(axiosWithCookies);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Run this in your browser console
2+
3+
document.addEventListener('scroll', () => {
4+
console.log('Scrolling...');
5+
});
6+
7+
// See what happens when you scroll
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const fs = require('fs');
2+
3+
fs.readdir('.', (err, data) => {
4+
// Shouldn't error
5+
console.assert(Boolean(data));
6+
console.assert(!err);
7+
});
8+
9+
fs.readdir('/tmp/nonexistent', (err, data) => {
10+
// Should error
11+
console.assert(!data);
12+
console.assert(Boolean(err));
13+
});

0 commit comments

Comments
 (0)