mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-06-08 02:37:13 +00:00
Fix typos
This commit is contained in:
parent
76550dfa3c
commit
5c0799df7f
118 changed files with 1150 additions and 1602 deletions
|
@ -20,8 +20,8 @@ var request = new XMLHttpRequest();
|
|||
request.addEventListener(event, function() {...});
|
||||
|
||||
request.open("HttpMethod", "path/to/api", true); // third parameter is asynchronicity (true = asynchronous)
|
||||
reqest.setRequestHeader(key, value) // HTTP Request Headers
|
||||
reqest.send()
|
||||
request.setRequestHeader(key, value) // HTTP Request Headers
|
||||
request.send()
|
||||
```
|
||||
|
||||
To check the status use `XMLHttpRequest.status` and `XMLHttpRequest.statusText`.
|
||||
|
@ -75,7 +75,7 @@ request.send();
|
|||
|
||||
### `XMLHttpRequest` Browser compatibility
|
||||
|
||||
Old versions of IE don’t implement XMLHttpRequest. You must use the ActiveXObject if XMLHttpRequest is not available
|
||||
Old versions of IE don't implement XMLHttpRequest. You must use the ActiveXObject if XMLHttpRequest is not available
|
||||
|
||||
```js
|
||||
var request =window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
|
||||
|
|
|
@ -26,7 +26,7 @@ var node = document.querySelector('css-selector');
|
|||
var nodes = document.querySelectorAll('css-selector');
|
||||
```
|
||||
|
||||
## Manupulating the DOM
|
||||
## Manipulating the DOM
|
||||
|
||||
### Manipulating a node's attributes
|
||||
|
||||
|
@ -43,7 +43,7 @@ var node = document.getElementById('id');
|
|||
node.className = 'new-class';
|
||||
```
|
||||
|
||||
### Manipulating a node’s style
|
||||
### Manipulating a node's style
|
||||
|
||||
It's possible to access and change the styles of a DOM nodes via the **style** property.
|
||||
CSS property names with a `-` must be **camelCased** and number properties must have a unit.
|
||||
|
@ -63,7 +63,7 @@ pageNode.style.backgroundColor = 'pink';
|
|||
pageNode.style.paddingTop = '10px';
|
||||
```
|
||||
|
||||
### Manipulating a node’s contents
|
||||
### Manipulating a node's contents
|
||||
|
||||
Each DOM node has an `innerHTML` attribute. It contains the HTML of all its children.
|
||||
|
||||
|
@ -103,7 +103,7 @@ In `page.html`:
|
|||
In `script.js`:
|
||||
|
||||
```js
|
||||
var formNode = document.getEleementById("Identifier");
|
||||
var formNode = document.getElementById("Identifier");
|
||||
var value = formNode.value;
|
||||
```
|
||||
|
||||
|
@ -123,7 +123,7 @@ domNode.insertBefore(childToInsert, domnode);
|
|||
domNode.parentNode.insertBefore(childToInsert, nodeAfterChild);
|
||||
|
||||
// remove a node
|
||||
domnNod.removeChild(childToRemove);
|
||||
domNode.removeChild(childToRemove);
|
||||
node.parentNode.removeChild(node);
|
||||
```
|
||||
|
||||
|
@ -152,7 +152,7 @@ body.appendChild(newParagraph);
|
|||
function Node(params) {
|
||||
this.node = document.createElement("tag");
|
||||
|
||||
this.node.attrubute = value;
|
||||
this.node.attribute = value;
|
||||
|
||||
// operations on the node
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ var onEvent = function(event) { // parameter contains info on the triggered eve
|
|||
// logic here
|
||||
}
|
||||
|
||||
domNode.addEventListener(eventType, calledback);
|
||||
domNode.renoveEventListener(eventType, callback);
|
||||
domNode.addEventListener(eventType, callback);
|
||||
domNode.removeEventListener(eventType, callback);
|
||||
```
|
||||
|
||||
### Bubbling & Capturing
|
||||
|
@ -44,7 +44,7 @@ let event = new CustomEvent(type, { detail: /* custom data */ }); // create eve
|
|||
domNode.dispatchEvent(event); // launch the event
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
## Animation
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
* @author author's name
|
||||
* purpose of file
|
||||
*
|
||||
* detailed explanantion of what the file does on multiple lines
|
||||
* detailed explanation of what the file does on multiple lines
|
||||
*/
|
||||
```
|
||||
|
||||
|
@ -56,7 +56,7 @@ alert("message");
|
|||
|
||||
[var vs let vs const](https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/)
|
||||
|
||||
Variable names can only contain numbers, digits, underscores and $. Varieble names are camelCase.
|
||||
Variable names can only contain numbers, digits, underscores and $. Variable names are camelCase.
|
||||
|
||||
`let`: Block-scoped; access to variable restricted to the nearest enclosing block.
|
||||
`var`: Function-scoped
|
||||
|
@ -66,8 +66,8 @@ Variable names can only contain numbers, digits, underscores and $. Varieble nam
|
|||
|
||||
### Scope
|
||||
|
||||
Variabled declared with `let` are in local to the code block in which are declared.
|
||||
Variabled declared with `var` are local only if declared in a function.
|
||||
Variable declared with `let` are in local to the code block in which are declared.
|
||||
Variable declared with `var` are local only if declared in a function.
|
||||
|
||||
```js
|
||||
function func(){
|
||||
|
@ -121,9 +121,9 @@ let string$ = 'text';
|
|||
let string_ = `text ${expression}`; //string interpolation (needs backticks)
|
||||
|
||||
string.length; // length of the string
|
||||
let char = string.charAt(index); // extaraction of a single character by position
|
||||
let char = string.charAt(index); // extraction of a single character by position
|
||||
string[index]; // char extraction by property access
|
||||
let index = strinf.indexOf(substring); // start index of substring in string
|
||||
let index = string.indexOf(substring); // start index of substring in string
|
||||
```
|
||||
|
||||
Property access is unpredictable:
|
||||
|
@ -170,7 +170,7 @@ typeof x; //returns the type of the variable x as a string
|
|||
typeof(x); //returns the type of the variable x as a string
|
||||
```
|
||||
|
||||
The result of typeof null is "object". That’s wrong.
|
||||
The result of typeof null is "object". That's wrong.
|
||||
It is an officially recognized error in typeof, kept for compatibility. Of course, null is not an object.
|
||||
It is a special value with a separate type of its own. So, again, this is an error in the language.
|
||||
|
||||
|
@ -179,12 +179,12 @@ It is a special value with a separate type of its own. So, again, this is an err
|
|||
```javascript
|
||||
String(value); //converts value to string
|
||||
|
||||
Number(value); //converst value to a number
|
||||
Number(value); //converts value to a number
|
||||
Number(undefined); //--> NaN
|
||||
Number(null); //--> 0
|
||||
Number(true); //--> 1
|
||||
Number(false); //--> 0
|
||||
Number(String); //Whitespaces from the start and end are removed. If the remaining string is empty, the result is 0. Otherwise, the number is “read” from the string. An error gives NaN.
|
||||
Number(String); //Whitespace from the start and end is removed. If the remaining string is empty, the result is 0. Otherwise, the number is "read" from the string. An error gives NaN.
|
||||
|
||||
Boolean(value); //--> true
|
||||
Boolean(0); //--> false
|
||||
|
@ -211,8 +211,8 @@ Number("A") == NaN; //false ?!?
|
|||
|
||||
```js
|
||||
2 + 'text'; //"2text", implicit conversion and concatenation
|
||||
1 + "1"; //"11", implicit conversion and concatention
|
||||
"1" + 1; //"11", implicit conversion and concatention
|
||||
1 + "1"; //"11", implicit conversion and concatenation
|
||||
"1" + 1; //"11", implicit conversion and concatenation
|
||||
+"1"; //1, implicit conversion
|
||||
+"text"; // NaN
|
||||
1 == "1"; //true
|
||||
|
@ -231,7 +231,7 @@ Number("A") == NaN; //false ?!?
|
|||
| `new` a(...) | object creation |
|
||||
| a `in` b | membership |
|
||||
|
||||
### Mathemetical Operators
|
||||
### Mathematical Operators
|
||||
|
||||
| Operator | Operation |
|
||||
| -------- | -------------- |
|
||||
|
@ -247,9 +247,9 @@ Number("A") == NaN; //false ?!?
|
|||
| Operator | Operation |
|
||||
| ------------ | ----------------- |
|
||||
| `--`variable | prefix decrement |
|
||||
| `++`variable | prefix incremente |
|
||||
| variable`--` | postfiz decrement |
|
||||
| variable`++` | ostfix increment |
|
||||
| `++`variable | prefix increment |
|
||||
| variable`--` | postfix decrement |
|
||||
| variable`++` | postfix increment |
|
||||
|
||||
### Logical Operators
|
||||
|
||||
|
@ -267,7 +267,7 @@ Number("A") == NaN; //false ?!?
|
|||
| a `<=` b | less or equal to |
|
||||
| a `>` b | greater than |
|
||||
| a `>=` b | greater or equal to |
|
||||
| a `==` b | equaltity |
|
||||
| a `==` b | equality |
|
||||
| a `!=` b | inequality |
|
||||
| a `===` b | strict equality |
|
||||
| a `!==` b | strict inequality |
|
||||
|
@ -281,8 +281,8 @@ Number("A") == NaN; //false ?!?
|
|||
| a `^` b | bitwise XOR |
|
||||
| `~`a | bitwise NOT |
|
||||
| a `<<` b | bitwise left shift |
|
||||
| a `>>` b | bitwise rigth sigt |
|
||||
| a `>>>` b | bitwise unsigned rigth shift |
|
||||
| a `>>` b | bitwise right shift |
|
||||
| a `>>>` b | bitwise unsigned right shift |
|
||||
|
||||
### Compound Operators
|
||||
|
||||
|
@ -364,19 +364,19 @@ do {
|
|||
### For Loop
|
||||
|
||||
```javascript
|
||||
// baseic for
|
||||
// basic for
|
||||
for (begin; condition; step) { }
|
||||
|
||||
for (var variable in iterable) { } // for/in statement loops through the properties of an object
|
||||
for (let variable in iterable) { } // inistatiate a new variable at each iteration
|
||||
for (let variable in iterable) { } // instantiate a new variable at each iteration
|
||||
|
||||
// for/of statement loops through the values of an iterable objects
|
||||
// for/of lets you loop over data structures that are iterable such as Arrays, Strings, Maps, NodeLists, and more.
|
||||
for (var variable of iterable) { }
|
||||
for (let variable of iterable) { } // inistatiate a new variable at each iteration
|
||||
for (let variable of iterable) { } // instantiate a new variable at each iteration
|
||||
|
||||
// foreach (similar to for..of)
|
||||
itearble.forEach(() => { /* statements */ });
|
||||
iterable.forEach(() => { /* statements */ });
|
||||
```
|
||||
|
||||
### Break & Continue statements
|
||||
|
@ -385,11 +385,11 @@ itearble.forEach(() => { /* statements */ });
|
|||
`continue;` skip to next loop cycle.
|
||||
|
||||
```javascript
|
||||
labelname: for(begin; condition; step) {
|
||||
label: for(begin; condition; step) {
|
||||
//code here
|
||||
}
|
||||
|
||||
break labelname; //breaks labelled loop and nested loops inside it
|
||||
break label; //breaks labelled loop and nested loops inside it
|
||||
```
|
||||
|
||||
## Arrays
|
||||
|
@ -405,9 +405,9 @@ array[index] = item; // change or add item by index
|
|||
array.push(item); //add item to array
|
||||
array.pop(); // remove and return last item
|
||||
|
||||
array.join("separator"); // constuct a string from the items of the array, sepatated by SEPARATOR
|
||||
array.join("separator"); // construct a string from the items of the array, separated by SEPARATOR
|
||||
array.find(item => condition); // returns the value of the first element in the provided array that satisfies the provided testing function
|
||||
array.fill(value, start, end); // filla an array with the passed value
|
||||
array.fill(value, start, end); // fills an array with the passed value
|
||||
|
||||
|
||||
// https://stackoverflow.com/a/37601776
|
||||
|
@ -438,7 +438,7 @@ let array1 = [ 1, 2, 3, 4, 5, 6 ];
|
|||
let array2 = [ 7, 8, 9, 10 ];
|
||||
let copy = [ ...array1 ]; // shallow copy
|
||||
let copyAndAdd = [ 0, ...array1, 7 ]; // insert all values in new array
|
||||
let merge = [ ...array1, ...attay2 ]; // merge the arrays contents in new array
|
||||
let merge = [ ...array1, ...array2 ]; // merge the arrays contents in new array
|
||||
|
||||
// objects
|
||||
let obj = { prop1: value1, prop2: value2 };
|
||||
|
@ -507,7 +507,7 @@ function functionName(parameter=default-value, ...args) {
|
|||
```javascript
|
||||
function functionName(parameters) {
|
||||
if (parameter == undefined) {
|
||||
paremeter = value;
|
||||
parameter = value;
|
||||
}
|
||||
|
||||
//code here
|
||||
|
@ -542,7 +542,7 @@ let func = input => expression;
|
|||
|
||||
func(); // function call
|
||||
|
||||
// rerurn object literal
|
||||
// return object literal
|
||||
let func = (value) => ({property: value});
|
||||
```
|
||||
|
||||
|
@ -550,7 +550,7 @@ let func = (value) => ({property: value});
|
|||
|
||||
An object is a collection of related data and/or functionality.
|
||||
|
||||
**Note**: It's not possible to transform a variable in an object simply by using the object assignement.
|
||||
**Note**: It's not possible to transform a variable in an object simply by using the object assignment.
|
||||
|
||||
```js
|
||||
let variable = value;
|
||||
|
@ -567,7 +567,7 @@ let obj = {
|
|||
|
||||
method: function() {
|
||||
// code here
|
||||
this.properyName; // reference to object property inside the object
|
||||
this.propertyName; // reference to object property inside the object
|
||||
}
|
||||
|
||||
method; () => {
|
||||
|
@ -575,7 +575,7 @@ let obj = {
|
|||
}
|
||||
};
|
||||
|
||||
// access to property (non existant porperties will return Undefined)
|
||||
// access to property (non existant properties will return Undefined)
|
||||
obj.property; // dot notation
|
||||
obj["property"]; // array notation
|
||||
|
||||
|
@ -601,12 +601,12 @@ Notice that it has all the features you'd expect in a function, although it does
|
|||
function Class(params) {
|
||||
this.property = param;
|
||||
|
||||
this.method = function(parms) { /* code here */ }
|
||||
this.method = function(params) { /* code here */ }
|
||||
}
|
||||
|
||||
let obj = new Class(params); // object instantiation
|
||||
|
||||
let obj = new Object(); // cretaes empty object
|
||||
let obj = new Object(); // creates empty object
|
||||
let obj = new Object({
|
||||
// JSON
|
||||
});
|
||||
|
@ -623,7 +623,7 @@ This is often referred to as a **prototype chain**, and explains why different o
|
|||
If a method is implemented on an object (and not it's prototype) then only that object will heve that method and not all the ones that come from the same prototype.
|
||||
|
||||
```js
|
||||
// constuctor function
|
||||
// constructor function
|
||||
function Obj(param1, ...) {
|
||||
this.param1 = param1,
|
||||
...
|
||||
|
@ -712,10 +712,10 @@ let obj = {
|
|||
|
||||
let { var1, var2 } = obj; // extract values from object into variables
|
||||
let { property: var1, property2 : var2 } = obj; // extract props in variables w/ specified names
|
||||
let { property: var1, var2 = defalut_value } = obj; // use default values if object has less then expected props
|
||||
let { property: var1, var2 = default_value } = obj; // use default values if object has less then expected props
|
||||
```
|
||||
|
||||
### Array Deconstrions
|
||||
### Array Deconstruction
|
||||
|
||||
```js
|
||||
let array = [ 1, 2, 3, 4, 5, 6 ];
|
||||
|
@ -726,10 +726,10 @@ let [first, , third, , seventh = "missing" ] = array; // extract specific value
|
|||
|
||||
```js
|
||||
let object = {
|
||||
// ojectt attributes
|
||||
// object attributes
|
||||
}
|
||||
|
||||
let json = JSON.stringify(object); // serialieze onbect in JSON
|
||||
let json = JSON.stringify(object); // serialize object in JSON
|
||||
|
||||
let json = { /* JSON */ };
|
||||
let object = JSON.parse(json); // deserialize to Object
|
||||
|
@ -757,7 +757,7 @@ let timerId = setTimeout(function(arg1, ...){
|
|||
|
||||
clearTimeout(timerId) // cancel execution
|
||||
|
||||
// exemple of multiple consecutive schedules
|
||||
// example of multiple consecutive schedules
|
||||
let list = [1 , 2, 3, 4, 5, 6, 7, 8, 9, 10, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]
|
||||
function useTimeout(pos=0) {
|
||||
|
||||
|
@ -766,7 +766,7 @@ function useTimeout(pos=0) {
|
|||
pos += 1; // update value for next call
|
||||
|
||||
if (pos < list.length) { // recursion exit condition
|
||||
useTimeout(pos); // schedule next call with new walue
|
||||
useTimeout(pos); // schedule next call with new value
|
||||
}
|
||||
}, 1_000, pos);
|
||||
}
|
||||
|
@ -777,7 +777,7 @@ useTimeout();
|
|||
### `let` vs `var` with `setTimeout`
|
||||
|
||||
```js
|
||||
// let instantitates a new variable for each iteration
|
||||
// let instantiates a new variable for each iteration
|
||||
for (let i = 0; i < 3; ++i) {
|
||||
setTimeout(function() {
|
||||
console.log(i);
|
||||
|
@ -923,7 +923,7 @@ In `page.html`
|
|||
In `module.js`:
|
||||
|
||||
```js
|
||||
// exporting indivisual fratures
|
||||
// exporting individual fractures
|
||||
export default function() {} // one per module
|
||||
export func = () => expression; // zero or more per module
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# React Router
|
||||
|
||||
Popular routing library. Allows to specify a route through React components, declating which component is to be loaded for a given URL.
|
||||
Popular routing library. Allows to specify a route through React components, declaring which component is to be loaded for a given URL.
|
||||
|
||||
Key Components:
|
||||
|
||||
- **Router**: wrap the app entrypoint, usually `BrowserRouter`
|
||||
- **Router**: wrap the app entry-point, usually `BrowserRouter`
|
||||
- **Route**: "Load this component for this URL"
|
||||
- **Link**: react-managed anchors that won't post back to the browser
|
||||
|
||||
|
@ -74,7 +74,7 @@ import { Redirect } from "react-router-dom";
|
|||
<Redirect from="/old-route" to="/new-route" />
|
||||
{ condition && <Redirect to="/route" /> } // redirect if condition is true
|
||||
|
||||
// or redirect manipolating the history (always in props)
|
||||
// or redirect manipulating the history (always in props)
|
||||
props.history.push("/new-route");
|
||||
```
|
||||
|
||||
|
@ -83,13 +83,13 @@ props.history.push("/new-route");
|
|||
```js
|
||||
import { Prompt } from "react-router-dom";
|
||||
|
||||
// displayes a prompt when the condition is true
|
||||
// displays a prompt when the condition is true
|
||||
<Prompt when={condition} message="prompt message" />
|
||||
```
|
||||
|
||||
## Link
|
||||
|
||||
Clicks on a link created with React-Router will be captured by ract an all the routing will happen client side.
|
||||
Clicks on a link created with React-Router will be captured by react an all the routing will happen client side.
|
||||
|
||||
```js
|
||||
import { Link } from "react-router-dom";
|
||||
|
|
|
@ -13,7 +13,7 @@ In `package.json`:
|
|||
"test": "jest --watch" // watch re-runs test on save
|
||||
},
|
||||
"jest": {
|
||||
// calls additional setups for enzyme, react tesing library, ...
|
||||
// calls additional setups for enzyme, react testing library, ...
|
||||
"setupFiles": [
|
||||
"path/to/testSetup.js"
|
||||
],
|
||||
|
@ -64,16 +64,16 @@ In `Component.Snapshots.js`:
|
|||
|
||||
```js
|
||||
import React from "react";
|
||||
import rederer from "react-test-renderer";
|
||||
import renderer from "react-test-renderer";
|
||||
|
||||
import Component from "./path/to/Component";
|
||||
// import mock data if necessary
|
||||
|
||||
it("test descrtiption", () => {
|
||||
it("test description", () => {
|
||||
// renders the DOM tree of the component
|
||||
const tree = renderer.create(<Component funcProp={jest.fn() /* mock function */} /* component props */ />);
|
||||
|
||||
// save a snaphot of the component at this point in time ( in __snaphsots__ folder)
|
||||
// save a snapshot of the component at this point in time ( in __snapshots__ folder)
|
||||
// in future test it will be checked to avoid regressions
|
||||
// can be updated during jest --watch pressing "u"
|
||||
expect(tree).matchSnapshot();
|
||||
|
@ -89,7 +89,7 @@ it("test descrtiption", () => {
|
|||
```js
|
||||
// testSetup.js
|
||||
import { configure } from "enzyme";
|
||||
import Adapter from "enzyme-adapert-react-<version>";
|
||||
import Adapter from "enzyme-adapter-react-<version>";
|
||||
|
||||
configure({ adapter: new Adapter() });
|
||||
```
|
||||
|
@ -128,7 +128,7 @@ it("test description", () => {
|
|||
});
|
||||
|
||||
// mount rendering test
|
||||
if("test descriotion" () => {
|
||||
if("test description" () => {
|
||||
const dom = mount(
|
||||
<WrapperComponent>
|
||||
<Component /* props *//>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## Components
|
||||
|
||||
Thera are two types of react components:
|
||||
There are two types of react components:
|
||||
|
||||
- Function Components
|
||||
- Class Components
|
||||
|
@ -29,7 +29,7 @@ class Component extends React.Component {
|
|||
|
||||
Every components has two inputs: *props* and *state*. The props input is explicit while the state is implicit. State is used to determine the chages. Within the component state can be changed while the props object represent fixed values.
|
||||
|
||||
JSX syntax can resable HTML bat gets converted to pure JavaScript before being sent to the browser:
|
||||
JSX syntax can reusable HTML bat gets converted to pure JavaScript before being sent to the browser:
|
||||
|
||||
```js
|
||||
// JSX
|
||||
|
@ -45,7 +45,7 @@ const element = React.createElement(
|
|||
);
|
||||
```
|
||||
|
||||
### App Entrypoint
|
||||
### App Entry-point
|
||||
|
||||
```js
|
||||
ReactDOM.render(
|
||||
|
@ -60,7 +60,7 @@ ReactDOM.render(
|
|||
### Dynamic Expressions
|
||||
|
||||
```js
|
||||
<tag>{expression}</tag> // expression is evalueted an it's result is displayed
|
||||
<tag>{expression}</tag> // expression is evaluated an it's result is displayed
|
||||
<tag onEvent={funcReference}>{expression}</tag>
|
||||
<tag onEvent={() => func(args)}>{expression}</tag>
|
||||
```
|
||||
|
@ -69,7 +69,7 @@ ReactDOM.render(
|
|||
|
||||
```js
|
||||
<Component propName={value} /> // pass a value the component
|
||||
<Component propName={funcreference} /> // pass a function to the component
|
||||
<Component propName={funcReference} /> // pass a function to the component
|
||||
|
||||
function Component(props) {
|
||||
// use props with {props.propName}
|
||||
|
@ -135,7 +135,7 @@ class Button extends React.Component {
|
|||
}
|
||||
```
|
||||
|
||||
### Nesting Compnents
|
||||
### Nesting Components
|
||||
|
||||
```js
|
||||
import { useState } from "react";
|
||||
|
@ -225,7 +225,7 @@ const [state, setState] = useState(default);
|
|||
|
||||
### `useEffect`
|
||||
|
||||
Hook used to trigger an action on each reder of the component or when one of the watched items changes.
|
||||
Hook used to trigger an action on each render of the component or when one of the watched items changes.
|
||||
|
||||
```js
|
||||
|
||||
|
@ -240,7 +240,7 @@ useEffect(() => {
|
|||
|
||||
```js
|
||||
// hook definitions
|
||||
const useCutomHook = () => {
|
||||
const useCustomHook = () => {
|
||||
// eventual state definitions
|
||||
|
||||
// eventual function definitions
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
## Tests for Connected Components
|
||||
|
||||
Connected components are warpped in a call to `connect`. Way of solving the problem:
|
||||
Connected components are wrapped in a call to `connect`. Way of solving the problem:
|
||||
|
||||
- Wrap component with `<Provider>`. Added benefit: new store dedicated to tests.
|
||||
- Add named export for unconncted component.
|
||||
- Add named export for unconnected component.
|
||||
|
||||
In `Component.js`:
|
||||
|
||||
|
@ -38,8 +38,8 @@ function testHelper(args) {
|
|||
it("test description", () => {
|
||||
const dom = testHelper();
|
||||
|
||||
// simulate page interation
|
||||
dom.find("selctor").simulate("<event>");
|
||||
// simulate page iteration
|
||||
dom.find("selector").simulate("<event>");
|
||||
|
||||
// find changed component
|
||||
// test expected behaviour of component
|
||||
|
@ -91,7 +91,7 @@ import initialState from "path/to/initialState";
|
|||
import * as actions from "path/to/actionCreators";
|
||||
|
||||
it("test description", () => {
|
||||
const store = createStore(toorReducer, initialState);
|
||||
const store = createStore(storeReducer, initialState);
|
||||
|
||||
const expectedState = /* state after the update */
|
||||
|
||||
|
@ -126,7 +126,7 @@ import * as actions from "path/to/actionCreators";
|
|||
|
||||
describe("Async Actions", () => {
|
||||
afterEach(() => {
|
||||
fetchMock.restore(); // init fecth mock for each test
|
||||
fetchMock.restore(); // init fetch mock for each test
|
||||
});
|
||||
|
||||
it("test description", () => {
|
||||
|
|
|
@ -57,7 +57,7 @@ export function configStore(initialState) {
|
|||
replaceReducer(newReducer); // replace an existing reducer, useful for Hot Reload
|
||||
store.dispatch(action); // trigger a state change based on an action
|
||||
store.subscribe(listener);
|
||||
store.getState(); // retireve current state
|
||||
store.getState(); // retrieve current state
|
||||
```
|
||||
|
||||
### Reducers
|
||||
|
@ -106,7 +106,7 @@ Container Components:
|
|||
- Subscribe to Redux State
|
||||
- Dispatch Redux actions
|
||||
|
||||
Presentaional Components:
|
||||
Presentational Components:
|
||||
|
||||
- Focus on how things look
|
||||
- Unaware of Redux
|
||||
|
@ -145,23 +145,23 @@ import { increment, decrement, reset } from './actionCreators';
|
|||
|
||||
// const Component = ...
|
||||
|
||||
// specifies which state is passed to the component (called on satte change)
|
||||
// specifies which state is passed to the component (called on state change)
|
||||
const mapStateToProps = (state, ownProps /* optional */) => {
|
||||
// structure of the props passsed to the component
|
||||
// structure of the props passed to the component
|
||||
return { propName: state.property };
|
||||
};
|
||||
|
||||
// specifies the action passed to a component (the key is the name that the prop will have )
|
||||
const mapDispatchToProps = { actionCreator: actionCreator };
|
||||
// or
|
||||
function mapDispathToProps(dispatch) {
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
// wrap action creators
|
||||
actionCreator: (args) => dispatch(actionCreator(args))
|
||||
};
|
||||
}
|
||||
// or
|
||||
function mapDispathToProps(dispatch) {
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
actionCreator: bindActionCreators(actionCreator, dispatch),
|
||||
actions: bindActionCreators(allActionCreators, dispatch)
|
||||
|
@ -177,7 +177,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(Component);
|
|||
|
||||
**Note**: Redux middleware runs *after* and action and *before* it's reducer.
|
||||
|
||||
Redux-Thunk allows to retrurn functions instead of objects from action creators.
|
||||
Redux-Thunk allows to return functions instead of objects from action creators.
|
||||
A "thunk" is a function that wraps an expression to delay it's evaluation.
|
||||
|
||||
In `configStore.js`:
|
||||
|
@ -199,7 +199,7 @@ function configStore(initialState) {
|
|||
```
|
||||
|
||||
```js
|
||||
// usally action on async func success
|
||||
// usually action on async func success
|
||||
function actionCreator(arg) {
|
||||
return { type: TYPE, data: arg };
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ node scripts/setupTypeScript.js
|
|||
npm init vite@latest
|
||||
```
|
||||
|
||||
## App Entrypoint
|
||||
## App Entry-point
|
||||
|
||||
```js
|
||||
import App from "./App.svelte"; // import the component
|
||||
|
@ -74,7 +74,7 @@ export default app;
|
|||
// markup here
|
||||
{/each}
|
||||
|
||||
{#each array as item (key)} // usse key to determine changes
|
||||
{#each array as item (key)} // use key to determine changes
|
||||
// markup here
|
||||
{/each}
|
||||
```
|
||||
|
@ -139,7 +139,7 @@ For these, Svelte has reactive declarations. They look like this:
|
|||
|
||||
```js
|
||||
let count = 0;
|
||||
$: double = count * 2; // recaclulatd when count changes
|
||||
$: double = count * 2; // recalculated when count changes
|
||||
// or
|
||||
$: { }
|
||||
$: <expression>
|
||||
|
|
|
@ -90,9 +90,9 @@ $('a').css({'color': 'purple'});
|
|||
### Create, Store, Manipulate and inject
|
||||
|
||||
```js
|
||||
let paragraph = $('<p class="intro">Welcome<p>'); // creat and store element
|
||||
let paragraph = $('<p class="intro">Welcome<p>'); // create and store element
|
||||
|
||||
paragraph.css('propery', 'value'); // manipulate element
|
||||
paragraph.css('property', 'value'); // manipulate element
|
||||
|
||||
$("body").append(paragraph); // inject in DOM
|
||||
```
|
||||
|
@ -148,7 +148,7 @@ In the HTML, add a `<script>` ag that hotlinks to the CDN or source file:
|
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"><script>
|
||||
```
|
||||
|
||||
In the JavaScript call the jQuery puging on the DOM:
|
||||
In the JavaScript call the jQuery plugin on the DOM:
|
||||
|
||||
```js
|
||||
$("form").validate();
|
||||
|
@ -195,7 +195,7 @@ banner.css('color', 'red')
|
|||
|
||||
### DOM Readiness
|
||||
|
||||
DOM manipulation and event binding doesn’t work if the `<script>` is in the `<head>`
|
||||
DOM manipulation and event binding doesn't work if the `<script>` is in the `<head>`
|
||||
|
||||
```js
|
||||
$(document).ready(function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue