@lingxiteam/ebe-utils 0.0.14 → 0.0.15

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.
@@ -11,10 +11,13 @@ interface LifeCycleOptions {
11
11
  const useLifeCyle = (options: LifeCycleOptions) => {
12
12
  const { mountCond = () => true, monutDeps, stateDeps } = options;
13
13
 
14
+ const timeoutRef = useRef<NodeJS.Timeout>();
15
+
14
16
  const lifeCycleCbRef = useRef({
15
17
  mount: () => {},
16
18
  unmounted: () => {},
17
19
  stateChange: () => {},
20
+ requestEnd: () => {},
18
21
  });
19
22
 
20
23
  const todoStateChanageRef = useRef(() => {});
@@ -30,6 +33,12 @@ const useLifeCyle = (options: LifeCycleOptions) => {
30
33
 
31
34
  // 页面加载完成后 执行一次组件状态变更
32
35
  todoStateChanageRef.current();
36
+
37
+ // FIXME: 生命周期临时解决方案 后续需要处理
38
+ timeoutRef.current = setTimeout(() => {
39
+ lifeCycleCbRef.current.requestEnd();
40
+ clearTimeout(timeoutRef.current);
41
+ }, 2000);
33
42
  }
34
43
  }
35
44
  }, monutDeps);
@@ -45,6 +54,7 @@ const useLifeCyle = (options: LifeCycleOptions) => {
45
54
  useEffect(
46
55
  () => () => {
47
56
  lifeCycleCbRef.current.unmounted();
57
+ clearTimeout(timeoutRef.current);
48
58
  },
49
59
  [],
50
60
  );
@@ -69,10 +79,15 @@ const useLifeCyle = (options: LifeCycleOptions) => {
69
79
  lifeCycleCbRef.current.stateChange = callback;
70
80
  };
71
81
 
82
+ const usePageEndRequest = (callback: () => void) => {
83
+ lifeCycleCbRef.current.requestEnd = callback;
84
+ };
85
+
72
86
  return {
73
87
  useMount,
74
88
  useUnmounted,
75
89
  useStateUpdate,
90
+ usePageEndRequest,
76
91
  };
77
92
  };
78
93