-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathredux-storage.redux.txt
52 lines (41 loc) · 2.78 KB
/
redux-storage.redux.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
┏━━━━━━━━━━━━━━━━━━━┓
┃ REDUX-STORAGE ┃
┗━━━━━━━━━━━━━━━━━━━┛
VERSION ==> #1.4.1
#[De]serialize Redux STATE (e.g. on localStorage)
┌──────────┐
│ BASE │
└──────────┘
RSTORAGE.createMiddleware
(ENGINE[, VAL_ARR][, VAL2_ARR]) #Does ENGINE.save(STATE) after each ACTION.
->REDUX_MDWR #VAL_ARR are blacklisted ACTION.type, VAL2_ARR whitelisted.
SAVE_ACTION #ACTION:
# - type RSTORAGE.SAVE
# - payload STATE
#Dispatched after ENGINE.save(STATE) but does not do anything by itself.
RSTORAGE.createLoader(ENGINE) #FUNC(STORE) does:
->FUNC(STORE) # - ENGINE.load(STATE)
# - dispatch LOAD_ACTION with STATE2
# - returns its PROMISE
LOAD_ACTION #ACTION:
# - type RSTORAGE.LOAD
# - payload STATE2
RSTORAGE.reducer #RFUNC which merges LOAD_ACTION.payload into STATE
┌─────────────┐
│ ENGINES │
└─────────────┘
ENGINE #Base class for what serializes STATE
ENGINE.load(STATE)->PROMISE #PROMISE must resolve with STATE2
ENGINE.save(STATE)->PROMISE #PROMISE must resolve with nothing
RLOCALSTORAGE('KEY') #ENGINE that uses localStorage.getItem|setItem('KEY') and JSON.stringify|parse(STATE)
RLOCALSTORAGEFAKEPROMISE('KEY') #Same for environments without ES6 promises
RREACTIVENATIVEASYNC('KEY') #ENGINE that uses React-Native AsyncStorage instead of localStorage
┌────────────────┐
│ DECORATORS │
└────────────────┘
RSTORAGE.debounce
(ENGINE, NUM)->ENGINE #Make ENGINE.save() debounce with NUM ms
RSTORAGE.filter
(ENGINE, 'VAR'[_ARR]_ARR)->ENGINE #Make ENGINE.save() use a deep copy of STATE, with only STATE.VAR. Use VAR_ARR for nested variables.
RSTORAGE.immutablejs
(ENGINE, 'VAR'[_ARR]_ARR)->ENGINE #Same for ENGINE.load(), and make new STATE a IMMUTABLE_MAP