-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathreact-refetch.flux.txt
75 lines (64 loc) · 4.83 KB
/
react-refetch.flux.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
┏━━━━━━━━━━━━━━━━━━━┓
┃ REACT-REFETCH ┃
┗━━━━━━━━━━━━━━━━━━━┛
VERSION ==> #0.6.0
#On new props, fire AJAX request and use response as props.
#Idea:
# - simple declarative syntax, bound to component using model
# - works for GET requests, but not other HTTP methods
# - deviation from Flux: model logic done in components instead of common stores:
# - components might fire duplicate AJAX requests
# - couple components with model handling
#Good for read-only applications.
┌─────────────┐
│ PROMISE │
└─────────────┘
RREFETCH.PromiseState #Same API as PROMISE except:
# - immutable: must create new RPROMISE to update it
# - new RREFETCH.PromiseState(...) -> RREFETCH.PromiseState.create(...)
# - has following members, specific for AJAX requests:
RPROMIS.pending|fullfiled|rejected#BOOL
RPROMISE.value #When fullfiled, response OBJ
RPROMISE.reason #When rejected, response OBJ.error|message (or OBJ is neither exist)
RPROMISE.meta.request|response #REQUEST|RESPONSE from WINDOW.fetch()
┌──────────────┐
│ REQUESTS │
└──────────────┘
HOC #FUNC(RTYPE)->RTYPE2
RREFETCH.connect #Adds PROPS.VAR RPROMISE:
(FUNC(PROPS)->CONF[, OPT])->HOC # - updated on AJAX request ongoing|fullfiled|rejected state change
# - fired on componentWillMount|componentWillReceiveProps:
# - unless same method+url+body+headers, unless:
# - CONF.force true
# - or using CONF.comparison VAL, which is then used for checking equality (using ===)
AJAX REQUEST CONF ==> #AJAX request uses CONF.VAR:
# - OBJ:
# - method STR (def: 'GET')
# - url STR
# - body STR
# - headers OBJ (def: { 'Accept|Content-Type': 'application/json' })
# - credentials STR (def: 'same-origin')
# - redirect STR (def: 'follow')
# - STR: same as { url STR }
# - FUNC2->CONF:
# - delay AJAX request (which will use CONF) until FUNC2 called
# - while delayed, assigns PROPS.VAR = FUNC2 (replaced by RPROMISE when fired)
AJAX REQUEST CHAINS ==> #After resolved|rejected, using CONF:
# - then|catch(RPROMISE.value|reason, RPROMISE.meta)->CONF_VAL:
# - become request chain last value
# - done before PROPS changed
# - andThen|Catch(RPROMISE.value|reason, RPROMISE.meta)->CONF:
# - creates new request chain
# - done after PROPS changed
UPDATE DURING SAME CYCLE ==> #CONF:
# - refreshInterval NUM:
# - redo the request each NUM seconds
# - while new request ongoing, RPROMISE.refreshing = true
# - refreshing true:
# - do not clear current PROPS.VAR while new request is ongoing
# - only necessary when PROPS.VAR updated several times during a single
# componentWillMount|componentWillReceiveProps cycle, e.g.:
# - delaying AJAX requests
# - AJAX request chains
RTYPE2.getWrappedInstance() #Returns RTYPE ELEM
#Must have used OPT.withRef true