Created: June 17, 2022 12:00 AM Created by: Anonymous Resources: https://www.youtube.com/watch?v=poQXNp9ItL4 Tags: Code
💡 Javascript is a multi paradigm language- easy testing
- readability of small functions
- chaining of functions
- comes also with a downside of making them more unreadable
- utility libraries like lodash help with this problem. (e.g pipe, compose) Lodash
- function currying:
- splitting arguments in chained fn’s (const curry = (a) ⇒ (b) => a+b )
- no random values
- no current date/time
- no global state (DOM, files, db, etc…)
- no mutations
- self-documenting
- easily testable
- concurrency
- cacheable
- Predictabilty
- Faster Change Detection
- Concurrency
- Performance
- memory overhead → “structural sharing”
- Immutable
- Immer
- Mori
- Action / Event
- Store
- Reducer / Event Handler
- data can’t be mutated like in normal javascript
- redux uses pure functions
- redux has no opinion our data
- takes a function with the store as argument to update the store
// reducer functions take the current instance of a store
// and return an updated version of it
store = {
categories: [],
products: [],
cart: {},
user: {},
};
function reducer(store, action) {
const updated = { ...store };
}
- User adds something to a shopping cart
- create an action object
- dispatch t o the store << dispatch(action) >>
- Store forwards the action to the reducer
- reducer isn’t called directly
- the store is in charge to call the reducer
- Reducer computes the new state and returns it
- The Store will set the state internally and notify the UI component
- Design the store
- define the actions
- create reducers
- set up the store