smsmslib 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/system/usereducer.js +58 -0
package/package.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {useReducer} from "react";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function sj_reducer_use(hf_type, o_init, f_init)
|
|
5
|
+
{
|
|
6
|
+
const [o_state, f_dispatch] = useReducer(sj_reducer, o_init, f_init);
|
|
7
|
+
const o_user = {};
|
|
8
|
+
const f_onAction = sj_reducer_onAction(hf_type, f_dispatch, o_user);
|
|
9
|
+
const o_reducer = new Reducer_t(o_state, f_onAction, o_user);
|
|
10
|
+
|
|
11
|
+
return o_reducer;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
function sj_reducer_onAction(hf_type, f_dispatch, o_user)
|
|
16
|
+
{
|
|
17
|
+
function onAction(o_event)
|
|
18
|
+
{
|
|
19
|
+
const s_type = o_event.target.dataset.s_type;
|
|
20
|
+
|
|
21
|
+
if ((s_type in hf_type) && (f_dispatch !== null))
|
|
22
|
+
{
|
|
23
|
+
const f_type = hf_type[s_type];
|
|
24
|
+
|
|
25
|
+
if (f_type !== null)
|
|
26
|
+
{
|
|
27
|
+
const o_action =
|
|
28
|
+
{
|
|
29
|
+
type : s_type, /* By convention. */
|
|
30
|
+
f_type : f_type,
|
|
31
|
+
o_event: o_event,
|
|
32
|
+
o_user : o_user,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
f_dispatch(o_action);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return onAction;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
function sj_reducer(o_state, o_action)
|
|
45
|
+
{
|
|
46
|
+
const o_next = o_action.f_type(o_state, o_action.o_event, o_action.o_user);
|
|
47
|
+
return o_next;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
function Reducer_t(o_state, f_onAction, o_user)
|
|
52
|
+
{
|
|
53
|
+
this.o_state = o_state;
|
|
54
|
+
this.f_onAction = f_onAction;
|
|
55
|
+
this.o_user = o_user;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|