-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnotes.txt
330 lines (250 loc) · 8.44 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
JavaScript
============================================================================
Line Oriented
Procedural
Object Based
Object Oriented (JS)
Functional (JS)
Function is a first class citizen
(Functions can be treated like data / object )
functions can be created like objects
functions can have attributes (like objects)
functions can have methods (like objects)
Support for Higher Order Functions
functions can be passed as arguments to other functions
functions can be returned from other functions
static
dynamic (JS)
strongly typed
loosely typed (JS)
JavaScript is a functional, dynamic and loosely typed language
Function invocation Patterns
- As a function
this => global (window)
- As a method of an object
this => object
- Using the 'call' method of the function
- Using the 'apply' method of the function
- As an 'Immediately invoked function expression' (IIFE)
- Using the 'new' keyword
this -> Invocation context
It does not matter WHERE the function is. What matters is how the function is invoked.
arguments
- implicit value available in all functions
- array like object containing all the argument values passed to the function
arguments.length -> the # of arguments passed to the function
arguments[0], arguments[1] .....
IBM-React-Nov-2020
Assignment-1
add()
add(10)
add(10,20,30,40,50)
add(10,'20',30,40,50)
add(10,'20','abc',30,40,50)
add([10,'20','abc'],[30,40,50])
add([10,'20','abc'],[30,[40,50]])
add(function(){ return [10,'20','abc'];},function(){ return [30,[40,50]]; })
add([function(){ return [10,'20','abc'];},function(){ return [30,[40,50]]; }])
add(function(){ return [function(){ return [10,'20','abc'];},function(){ return [30,[40,50]]; }];})
Closures
================================================================
ClickTracker.html
A button 'Track'
Everytime the 'Track' button is clicked, the page has to count the number of times the button is clicked and display to the user
Assignment-2
(THIS DOESNOT INVOLE HTML, BUTTON, CLICK EVENT HANDLER ETC)
var spinner = /*................................*/
//spinner must be an object with two methods - up() & down()
spinner.up() // => 1
spinner.up() // => 2
spinner.up() // => 3
spinner.up() // => 4
spinner.down() // => 3
spinner.down() // => 2
spinner.down() // => 1
spinner.down() // => 0
spinner.down() // => -1
Important :
There should NO other way by which the outcome of up & down methods can be influenced
For ex:
The following SHOULD NOT BE POSSIBLE
spinner.count = 10000
spinner.up() // => 10001
window.count = 10000
spinner.up() // => 10001
Constructor functions
===============================
Function invoked using the 'new' keyword
1. this -> new object
2. this -> returned by default
Convention : the constructor function name should start with an uppercase
Prototypal Inheritance
===================================
One object (prototype) acts as the base object for a family of objects
Attributes are resolved using 'prototype hopping'
'prototype hopping' happens ONLY when the attribute is READ
Videos for reference:
http://bit.ly/javascript-training-videos
ES6 (ESNext, ES2015)
================================
1. let
2. const
3. Array destructuring
4. Rest Operator (Array)
5. Spread operator (Array)
6. Object destructuring
7. Rest Operator (Object)
8. Spread operator (Object)
9. Default arguments
10. Arrow functions
11. Template strings
12. Class
http://es6-features.org
React
- A library for creating UI for the browser
- Presentation + Data + User Interaction
User Interacts -> Model Changes -> Presentation Updated
Application = Composition of Components
Component
represents one small part of the UI
Presentation + Data + User Interaction
Virtual DOM
HTML vs JSX
==================================
HTML
Open tags without close tags are allowed
'class' attribute is allowed
'for' attribute is allowed
JSX
All open tags must have the corresponding close tag
Use 'className' instead of 'class'
Use 'htmlFor' instead of 'for'
Assignment - 3
3-Nov 2:50PM
Assignment - 4
3-Nov 5:10PM
Assignment - 5
4-Nov - 10:35AM
Assignment - 6
5-Nov - 12:00PM
Assignment - 7
5-Nov - anytime
UI State & App State
UI State
- any data that supports the presentation logic of the component
- it is highly UNLIKELY that this data would be needed in other parts of the application
- Feel free to maintain this data in the component state
App State
- any data that supports the core business logic of the application
- it is highly LIKELY that this data would be needed in other parts of the application
- DO NOT maintain this data in the component state, instead maintain the data outside the component hierarchy
ES6 Modules
- anything defined in a js file is considered 'private'
- any 'public' entity has to explicitly 'export'ed.
- any public entity has to explicity 'import'ed to use in other js files
ES6 Module examples
/*
import * as calculator from './math';
console.log(calculator);
*/
/*
//import * as calculator from './math';
//calculator.add(10,20)
//const add = calculator.add;
//const { add } = calculator;
import { add } from './math'
add(10,20)
*/
//importing default exported object
/*
import calculator from './math';
calculator.add(10,20);
*/
./Products
./actions
./views
./index.js
Products component
./reducers
productsReducer.js
./store
./index.js
./index.js
There are only two places where you have access to the whole store state
1. mapStateToProps
Use this if you want to have access to the data in the store state for presentation
2.
Container Component / Smart Component
interface with the redux infrastructure to get the data and create action dispatchers
and cascade them to the child components
ex, Products, Categories
Presentation Component / Dumb Component
Receive data & action dispatchers from the parent component
Best Practice : Fewer container and any number of presentation components
Async Operation
- That will complete in future and one doesnt wait for its completion
Promise
- An object designed to hold the result of an async operation and make the result available whenever it is needed
- Other ways of handling async operations
callbacks
events
async await
generators
observables
axios
- promise based server communication library
React Hooks
- functions to handle side effects in functional component
- hook function names must start with 'use'
- builtin hooks
useState
useReducer
useEffect
useMemo
useCallback
Component Lifecycle Events
Created
componentWillMount
componentDidMount
Updated
shouldComponentUpdate
componentDidUpdate
Removed
componentWillUnmount
Routing
Displaying components based on the URL
Route - URL to component mapping
Build Steps
1. ES6 compilation
2. minify JS
3. uglify JS
4. bundle JS
5. version JS
6. minify CSS
7. bundle CSS
8. version CSS
9. update the references of generated JS file(s) in the index.html
10. update the references of generated CSS file(s) in the index.html
11. minify the index.html
12. copy the generated files to the build folder
Webpack bundler
Reference
http://bit.ly/javascript-training-videos
http://bit.ly/react-videos
Assignment:
Implement the 'Shopping Cart'
Add a 'Add To Cart' button for each product
On clicking the button the product has to be added to the cart
If the product is already in the cart, increment the count
Save the cart info in the server whenever a product is added/removed from the cart
Add a menu 'Cart'
This menu has to display the number of items in the cart ( such as 'Cart[3]')
On click of this menu, display the contents of the cart
Add a 'Remove' button for each item and remove the item when the button is clicked
Evaluation Parameters
Implementation
Modularity
Naming Conventions
Bugs
Comments
Deadline - EOD 11-Nov-2020