Redux(1)---Three Principles and Concepts

Basic

1. Echo $PATH

Show all shell scripts path

If you have 2 folders that contain the same command, it will run the first one

1
2
3
4
which cal //show which folder which is in
date -u
cal 2017
cal 12 2017

2. params

1
2
3
date -u - for short form
date --universal -- for long form
cal -A 1 -B 1 12 2017

3. file

1
2
3
4
touch 
cat
vim
ls -a

##Manual Structure

1
2
3
4
5
6
7
8
9
10
11
12
13
man -k which
man 1 which

WHICH(1) BSD General Commands Manual WHICH(1)

NAME
which -- locate a program file in the user's path

SYNOPSIS
which [-as] program ... (we can give more than one param)


which [-a | -f ] <something> #| means one of them, <> is mandatory [] is optional

###help page

man cd : no result

help cd : show cd info

just type help and it will show the command that needs help

The only way to change the state is to emit an action, an object describing what happened.
###cat
0:input
1:output
2:error

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
cat > output.txt // create a file and then put data stream out this file

cat >> output.txt // append to the file

some commands 2> error.txt //execute commands and then write errors into that file

tty //show the location of current terminal

cat < input.txt > {the url we got from last command} // show input.txt into that terminal
```

#### 3. Changes are made with pure functions
To specify how the state tree is transformed by actions, you write pure reducers.
- Redux assumes you never mutate your data.
- Redux does not have the concept of a Dispatcher. This is because it relies on pure functions instead of event emitters, and pure functions are easy to compose and don't need an additional entity managing them.
- Redux doesn't care how you store the state—it can be a plain object, an Immutable object, or anything else.

## Three Concepts
#### 1. Action
Actions are payloads of information that send data from your application to your store. They are the only source of information for the store. You send them to the store using store.dispatch().
- Actions must have a <strong>type</strong> property that indicates the type of action being performed.

#### 2. Reducer
Reducers specify how the application's state changes in response to actions sent to the store. Remember that actions only describe what happened, but don't describe how the application's state changes.
- It's called a reducer because it's the type of function you would pass to Array.prototype.reduce(reducer, ?initialValue).

#### Things you should never do inside a reducer:

- Mutate its arguments;
- Perform side effects like API calls and routing transitions;
- Call non-pure functions, e.g. Date.now() or Math.random().

> We'll explore how to perform side effects in the advanced walkthrough. For now, just remember that the reducer must be pure. Given the same arguments, it should calculate the next state and return it. No surprises. No side effects. No API calls. No mutations. Just a calculation.

#### 3. Store
The Store is the object that brings <strong>Actions</strong> and <strong>Reducers</strong> together.

The store has the following responsibilities:
- Holds application state;
- Allows access to state via getState();
- Allows state to be updated via dispatch(action);
- Registers listeners via subscribe(listener);
- Handles unregistering of listeners via the function returned by subscribe(listener).
``` javascript
import { createStore } from 'redux'
import todoApp from './reducers'
const store = createStore(todoApp)

It’s important to note that you’ll only have a single store in a Redux application. When you want to split your data handling logic, you’ll use reducer composition instead of many stores.

https://redux.js.org/introduction/three-principles
Learning Resources: https://redux.js.org/introduction/learning-resources