@ray-js/lamp-schedule-core 1.0.0-beta-1
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/README.md +565 -0
- package/lib/config/dpCodes.d.ts +27 -0
- package/lib/config/dpCodes.js +30 -0
- package/lib/config/index.d.ts +2 -0
- package/lib/config/index.js +2 -0
- package/lib/config/rhythms/defaultValue.d.ts +18 -0
- package/lib/config/rhythms/defaultValue.js +72 -0
- package/lib/config/rhythms/index.d.ts +10 -0
- package/lib/config/rhythms/index.js +35 -0
- package/lib/conflict/ConflictResolver.d.ts +2 -0
- package/lib/conflict/ConflictResolver.js +284 -0
- package/lib/conflict/__test__/ConflictResolver.test.d.ts +1 -0
- package/lib/conflict/__test__/ConflictResolver.test.js +183 -0
- package/lib/conflict/__test__/index.test.d.ts +1 -0
- package/lib/conflict/__test__/index.test.js +385 -0
- package/lib/conflict/__test__/scheduleDataManager.test.d.ts +1 -0
- package/lib/conflict/__test__/scheduleDataManager.test.js +170 -0
- package/lib/conflict/__test__/transform.test.d.ts +1 -0
- package/lib/conflict/__test__/transform.test.js +454 -0
- package/lib/conflict/__test__/updateDeviceDp.d.ts +1 -0
- package/lib/conflict/__test__/updateDeviceDp.js +114 -0
- package/lib/conflict/index.d.ts +42 -0
- package/lib/conflict/index.js +103 -0
- package/lib/conflict/scheduleDataManager.d.ts +12 -0
- package/lib/conflict/scheduleDataManager.js +79 -0
- package/lib/conflict/transform.d.ts +71 -0
- package/lib/conflict/transform.js +251 -0
- package/lib/conflict/type.d.ts +55 -0
- package/lib/conflict/type.js +17 -0
- package/lib/conflict/updateDeviceDp.d.ts +1 -0
- package/lib/conflict/updateDeviceDp.js +41 -0
- package/lib/constant/index.d.ts +5 -0
- package/lib/constant/index.js +5 -0
- package/lib/context/index.d.ts +3 -0
- package/lib/context/index.js +3 -0
- package/lib/context/rhythms/actions.d.ts +20 -0
- package/lib/context/rhythms/actions.js +52 -0
- package/lib/context/rhythms/index.d.ts +5 -0
- package/lib/context/rhythms/index.js +51 -0
- package/lib/context/rhythms/reducer.d.ts +24 -0
- package/lib/context/rhythms/reducer.js +38 -0
- package/lib/context/schedule/actions.d.ts +7 -0
- package/lib/context/schedule/actions.js +51 -0
- package/lib/context/schedule/context.d.ts +6 -0
- package/lib/context/schedule/context.js +52 -0
- package/lib/context/schedule/index.d.ts +1 -0
- package/lib/context/schedule/index.js +1 -0
- package/lib/context/schedule/reducer.d.ts +16 -0
- package/lib/context/schedule/reducer.js +104 -0
- package/lib/context/schedule/type.d.ts +41 -0
- package/lib/context/schedule/type.js +11 -0
- package/lib/context/timer/actions.d.ts +8 -0
- package/lib/context/timer/actions.js +52 -0
- package/lib/context/timer/context.d.ts +10 -0
- package/lib/context/timer/context.js +53 -0
- package/lib/context/timer/index.d.ts +1 -0
- package/lib/context/timer/index.js +1 -0
- package/lib/context/timer/reducer.d.ts +15 -0
- package/lib/context/timer/reducer.js +70 -0
- package/lib/context/timer/type.d.ts +46 -0
- package/lib/context/timer/type.js +24 -0
- package/lib/dpParser/README.md +63 -0
- package/lib/dpParser/__test__/cycle.test.d.ts +1 -0
- package/lib/dpParser/__test__/cycle.test.js +258 -0
- package/lib/dpParser/__test__/random.test.d.ts +1 -0
- package/lib/dpParser/__test__/random.test.js +211 -0
- package/lib/dpParser/__test__/rhythms.test.d.ts +1 -0
- package/lib/dpParser/__test__/rhythms.test.js +71 -0
- package/lib/dpParser/__test__/rtcTimer.test.d.ts +1 -0
- package/lib/dpParser/__test__/rtcTimer.test.js +235 -0
- package/lib/dpParser/__test__/sleep.test.d.ts +1 -0
- package/lib/dpParser/__test__/sleep.test.js +71 -0
- package/lib/dpParser/__test__/sleepCommon.test.d.ts +1 -0
- package/lib/dpParser/__test__/sleepCommon.test.js +197 -0
- package/lib/dpParser/__test__/timerReport.test.d.ts +1 -0
- package/lib/dpParser/__test__/timerReport.test.js +100 -0
- package/lib/dpParser/__test__/wakeup.test.d.ts +1 -0
- package/lib/dpParser/__test__/wakeup.test.js +69 -0
- package/lib/dpParser/__test__/wakeupCommon.test.d.ts +1 -0
- package/lib/dpParser/__test__/wakeupCommon.test.js +131 -0
- package/lib/dpParser/cycle/index.d.ts +15 -0
- package/lib/dpParser/cycle/index.js +134 -0
- package/lib/dpParser/index.d.ts +23 -0
- package/lib/dpParser/index.js +43 -0
- package/lib/dpParser/random/index.d.ts +15 -0
- package/lib/dpParser/random/index.js +127 -0
- package/lib/dpParser/rhythms.d.ts +41 -0
- package/lib/dpParser/rhythms.js +116 -0
- package/lib/dpParser/rtcTimer.d.ts +17 -0
- package/lib/dpParser/rtcTimer.js +300 -0
- package/lib/dpParser/sleep/index.d.ts +9 -0
- package/lib/dpParser/sleep/index.js +29 -0
- package/lib/dpParser/sleep/sleepCommon.d.ts +11 -0
- package/lib/dpParser/sleep/sleepCommon.js +117 -0
- package/lib/dpParser/sleep/sleepSigmesh.d.ts +0 -0
- package/lib/dpParser/sleep/sleepSigmesh.js +101 -0
- package/lib/dpParser/timerReport.d.ts +11 -0
- package/lib/dpParser/timerReport.js +43 -0
- package/lib/dpParser/utils.d.ts +27 -0
- package/lib/dpParser/utils.js +53 -0
- package/lib/dpParser/wakeup/index.d.ts +10 -0
- package/lib/dpParser/wakeup/index.js +34 -0
- package/lib/dpParser/wakeup/wakeupCommon.d.ts +11 -0
- package/lib/dpParser/wakeup/wakeupCommon.js +106 -0
- package/lib/dpParser/wakeup/wakeupSigmesh.d.ts +15 -0
- package/lib/dpParser/wakeup/wakeupSigmesh.js +86 -0
- package/lib/hooks/__test__/useCommon.test.d.ts +1 -0
- package/lib/hooks/__test__/useCommon.test.js +72 -0
- package/lib/hooks/__test__/useCountdownDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useCountdownDp.test.js +82 -0
- package/lib/hooks/__test__/useCycleDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useCycleDp.test.js +92 -0
- package/lib/hooks/__test__/useRandomDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useRandomDp.test.js +88 -0
- package/lib/hooks/__test__/useRhythmsDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useRhythmsDp.test.js +81 -0
- package/lib/hooks/__test__/useSleepDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useSleepDp.test.js +127 -0
- package/lib/hooks/__test__/useTimeFlush.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimeFlush.test.js +109 -0
- package/lib/hooks/__test__/useTimerDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerDp.test.js +79 -0
- package/lib/hooks/__test__/useTimerOperate.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperate.test.js +286 -0
- package/lib/hooks/__test__/useTimerOperateCloud.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperateCloud.test.js +190 -0
- package/lib/hooks/__test__/useTimerOperateLocal.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperateLocal.test.js +216 -0
- package/lib/hooks/__test__/useTimerReportDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerReportDp.test.js +93 -0
- package/lib/hooks/__test__/useTimerSupport.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerSupport.test.js +110 -0
- package/lib/hooks/__test__/useWakeUpDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useWakeUpDp.test.js +129 -0
- package/lib/hooks/useBaseLightDp.d.ts +21 -0
- package/lib/hooks/useBaseLightDp.js +165 -0
- package/lib/hooks/useCommon.d.ts +29 -0
- package/lib/hooks/useCommon.js +59 -0
- package/lib/hooks/useCommonSupport.d.ts +25 -0
- package/lib/hooks/useCommonSupport.js +241 -0
- package/lib/hooks/useCountdownDp.d.ts +13 -0
- package/lib/hooks/useCountdownDp.js +28 -0
- package/lib/hooks/useCountdownSupport.d.ts +9 -0
- package/lib/hooks/useCountdownSupport.js +13 -0
- package/lib/hooks/useCycleDp.d.ts +7 -0
- package/lib/hooks/useCycleDp.js +21 -0
- package/lib/hooks/useCycleSupport.d.ts +12 -0
- package/lib/hooks/useCycleSupport.js +16 -0
- package/lib/hooks/useRandomDp.d.ts +7 -0
- package/lib/hooks/useRandomDp.js +21 -0
- package/lib/hooks/useRandomSupport.d.ts +12 -0
- package/lib/hooks/useRandomSupport.js +16 -0
- package/lib/hooks/useRhythmsDp.d.ts +7 -0
- package/lib/hooks/useRhythmsDp.js +23 -0
- package/lib/hooks/useSleepDp.d.ts +6 -0
- package/lib/hooks/useSleepDp.js +21 -0
- package/lib/hooks/useSleepSupport.d.ts +8 -0
- package/lib/hooks/useSleepSupport.js +13 -0
- package/lib/hooks/useTimeFlush.d.ts +8 -0
- package/lib/hooks/useTimeFlush.js +31 -0
- package/lib/hooks/useTimerDp.d.ts +5 -0
- package/lib/hooks/useTimerDp.js +25 -0
- package/lib/hooks/useTimerFlushList.d.ts +11 -0
- package/lib/hooks/useTimerFlushList.js +53 -0
- package/lib/hooks/useTimerOperate.d.ts +68 -0
- package/lib/hooks/useTimerOperate.js +403 -0
- package/lib/hooks/useTimerOperateCloud.d.ts +31 -0
- package/lib/hooks/useTimerOperateCloud.js +233 -0
- package/lib/hooks/useTimerOperateLocal.d.ts +40 -0
- package/lib/hooks/useTimerOperateLocal.js +310 -0
- package/lib/hooks/useTimerReportDp.d.ts +15 -0
- package/lib/hooks/useTimerReportDp.js +48 -0
- package/lib/hooks/useTimerSupport.d.ts +13 -0
- package/lib/hooks/useTimerSupport.js +38 -0
- package/lib/hooks/useWakeUpDp.d.ts +6 -0
- package/lib/hooks/useWakeUpDp.js +21 -0
- package/lib/hooks/useWakeUpSupport.d.ts +8 -0
- package/lib/hooks/useWakeUpSupport.js +13 -0
- package/lib/hooks/useWakeupDp.d.ts +6 -0
- package/lib/hooks/useWakeupDp.js +21 -0
- package/lib/hooks/useWakeupSupport.d.ts +8 -0
- package/lib/hooks/useWakeupSupport.js +13 -0
- package/lib/i18n/index.d.ts +142 -0
- package/lib/i18n/index.js +7 -0
- package/lib/i18n/rhythms.d.ts +73 -0
- package/lib/i18n/rhythms.js +72 -0
- package/lib/i18n/strings.d.ts +73 -0
- package/lib/i18n/strings.js +6 -0
- package/lib/index.d.ts +51 -0
- package/lib/index.js +64 -0
- package/lib/types/countdown.d.ts +3 -0
- package/lib/types/countdown.js +1 -0
- package/lib/types/cycle.d.ts +22 -0
- package/lib/types/cycle.js +1 -0
- package/lib/types/global.d.ts +9 -0
- package/lib/types/index.d.ts +331 -0
- package/lib/types/index.js +76 -0
- package/lib/types/random.d.ts +20 -0
- package/lib/types/random.js +1 -0
- package/lib/types/rhythms.d.ts +79 -0
- package/lib/types/rhythms.js +15 -0
- package/lib/types/sleep.d.ts +36 -0
- package/lib/types/sleep.js +1 -0
- package/lib/types/timer.d.ts +107 -0
- package/lib/types/timer.js +1 -0
- package/lib/types/wakeup.d.ts +38 -0
- package/lib/types/wakeup.js +1 -0
- package/lib/utils/ScheduleCache.d.ts +19 -0
- package/lib/utils/ScheduleCache.js +39 -0
- package/lib/utils/ScheduleCloudProperty.d.ts +75 -0
- package/lib/utils/ScheduleCloudProperty.js +220 -0
- package/lib/utils/ScheduleDataSync.d.ts +82 -0
- package/lib/utils/ScheduleDataSync.js +127 -0
- package/lib/utils/ScheduleEmit.d.ts +67 -0
- package/lib/utils/ScheduleEmit.js +61 -0
- package/lib/utils/ScheduleLogger.d.ts +19 -0
- package/lib/utils/ScheduleLogger.js +71 -0
- package/lib/utils/ScheduleSupport.d.ts +131 -0
- package/lib/utils/ScheduleSupport.js +373 -0
- package/lib/utils/ScheduleUtils.d.ts +12 -0
- package/lib/utils/ScheduleUtils.js +51 -0
- package/lib/utils/__test__/ScheduleCloudProperty.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleCloudProperty.test.js +320 -0
- package/lib/utils/__test__/ScheduleSupport.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleSupport.test.js +211 -0
- package/lib/utils/__test__/ScheduleUtils.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleUtils.test.js +119 -0
- package/lib/utils/__test__/common.test.d.ts +1 -0
- package/lib/utils/__test__/common.test.js +147 -0
- package/lib/utils/__test__/storage.test.d.ts +1 -0
- package/lib/utils/__test__/storage.test.js +98 -0
- package/lib/utils/__test__/time.test.d.ts +1 -0
- package/lib/utils/__test__/time.test.js +146 -0
- package/lib/utils/common.d.ts +23 -0
- package/lib/utils/common.js +109 -0
- package/lib/utils/dpState.d.ts +5 -0
- package/lib/utils/dpState.js +27 -0
- package/lib/utils/getCachedSystemInfo.d.ts +39 -0
- package/lib/utils/getCachedSystemInfo.js +20 -0
- package/lib/utils/isInIDE.d.ts +1 -0
- package/lib/utils/isInIDE.js +5 -0
- package/lib/utils/storage.d.ts +5 -0
- package/lib/utils/storage.js +32 -0
- package/lib/utils/time.d.ts +40 -0
- package/lib/utils/time.js +84 -0
- package/package.json +78 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { scheduleLogger as ScheduleLogger } from '../../utils/ScheduleLogger';
|
|
2
|
+
import { ERhythm } from '../../types/rhythms';
|
|
3
|
+
export const updateRhythmsMessage = data => {
|
|
4
|
+
ScheduleLogger.debug(ERhythm.UPDATE_RHYTHMS_MESSAGE, data);
|
|
5
|
+
return {
|
|
6
|
+
type: ERhythm.UPDATE_RHYTHMS_MESSAGE,
|
|
7
|
+
payload: data
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export const updateRhythms = data => {
|
|
11
|
+
ScheduleLogger.debug(ERhythm.UPDATE_RHYTHMS, data);
|
|
12
|
+
return {
|
|
13
|
+
type: ERhythm.UPDATE_RHYTHMS,
|
|
14
|
+
payload: data
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export const updateLocalMessage = data => {
|
|
18
|
+
ScheduleLogger.debug(ERhythm.UPDATE_LOCAL_MESSAGE, data);
|
|
19
|
+
return {
|
|
20
|
+
type: ERhythm.UPDATE_LOCAL_MESSAGE,
|
|
21
|
+
payload: data
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export const updateUI = data => {
|
|
25
|
+
ScheduleLogger.debug(ERhythm.UPDATE_UI, data);
|
|
26
|
+
return {
|
|
27
|
+
type: ERhythm.UPDATE_UI,
|
|
28
|
+
payload: data
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export const initSystemInfo = data => {
|
|
32
|
+
ScheduleLogger.debug(ERhythm.INIT_SYSTEM_INFO, data);
|
|
33
|
+
return {
|
|
34
|
+
type: ERhythm.INIT_SYSTEM_INFO,
|
|
35
|
+
payload: data
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export const updateDp = data => {
|
|
39
|
+
ScheduleLogger.debug(ERhythm.UPDATE_DP, data);
|
|
40
|
+
return {
|
|
41
|
+
type: ERhythm.UPDATE_DP,
|
|
42
|
+
payload: data
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export default {
|
|
46
|
+
updateLocalMessage,
|
|
47
|
+
updateRhythms,
|
|
48
|
+
updateRhythmsMessage,
|
|
49
|
+
updateUI,
|
|
50
|
+
initSystemInfo,
|
|
51
|
+
updateDp
|
|
52
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
import { useRhythmReducer } from './reducer';
|
|
4
|
+
import actions from './actions';
|
|
5
|
+
const defaultRhythmData = {
|
|
6
|
+
localMessage: {
|
|
7
|
+
name: 'Hawaii',
|
|
8
|
+
latitude: 19.890355814979408,
|
|
9
|
+
longitude: 155.58935458466593
|
|
10
|
+
},
|
|
11
|
+
// name lon lat
|
|
12
|
+
rhythms: [],
|
|
13
|
+
// 3个数组
|
|
14
|
+
rhythmsMessage: {
|
|
15
|
+
power: false,
|
|
16
|
+
mode: 0,
|
|
17
|
+
isEnable: false
|
|
18
|
+
},
|
|
19
|
+
systemInfo: {},
|
|
20
|
+
dpState: {}
|
|
21
|
+
};
|
|
22
|
+
const RhythmContext = /*#__PURE__*/React.createContext({
|
|
23
|
+
state: defaultRhythmData,
|
|
24
|
+
dispatch: () => null,
|
|
25
|
+
props: {
|
|
26
|
+
devId: '',
|
|
27
|
+
autoShowTip: false,
|
|
28
|
+
needPutControlData: false,
|
|
29
|
+
onSave: () => null,
|
|
30
|
+
onCancel: () => null
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
let _rhythmsState = defaultRhythmData;
|
|
34
|
+
export const ContextProvider = props => {
|
|
35
|
+
const [state, dispatch] = useRhythmReducer(defaultRhythmData);
|
|
36
|
+
_rhythmsState = _objectSpread(_objectSpread({}, _rhythmsState), state);
|
|
37
|
+
return /*#__PURE__*/React.createElement(RhythmContext.Provider, {
|
|
38
|
+
value: {
|
|
39
|
+
state,
|
|
40
|
+
actions,
|
|
41
|
+
dispatch,
|
|
42
|
+
props: (props === null || props === void 0 ? void 0 : props.props) || {}
|
|
43
|
+
}
|
|
44
|
+
}, props.children);
|
|
45
|
+
};
|
|
46
|
+
export const useRhythmContext = () => {
|
|
47
|
+
return useContext(RhythmContext);
|
|
48
|
+
};
|
|
49
|
+
export const getRhythmsState = () => {
|
|
50
|
+
return _rhythmsState;
|
|
51
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IState } from '../../types/rhythms';
|
|
3
|
+
export declare const useRhythmReducer: (init: IState) => [IState | {
|
|
4
|
+
localMessage: Partial<IState> | undefined;
|
|
5
|
+
rhythms: [] | import("../../types/rhythms").TRhythmData[];
|
|
6
|
+
rhythmsMessage: import("../../types/rhythms").RhythmMessage;
|
|
7
|
+
systemInfo: any;
|
|
8
|
+
dpState: Record<string, any>;
|
|
9
|
+
} | {
|
|
10
|
+
rhythms: Partial<IState> | undefined;
|
|
11
|
+
localMessage: import("../../types/rhythms").LocalMessage;
|
|
12
|
+
rhythmsMessage: import("../../types/rhythms").RhythmMessage;
|
|
13
|
+
systemInfo: any;
|
|
14
|
+
dpState: Record<string, any>;
|
|
15
|
+
} | {
|
|
16
|
+
rhythmsMessage: Partial<IState> | undefined;
|
|
17
|
+
localMessage: import("../../types/rhythms").LocalMessage;
|
|
18
|
+
rhythms: [] | import("../../types/rhythms").TRhythmData[];
|
|
19
|
+
systemInfo: any;
|
|
20
|
+
dpState: Record<string, any>;
|
|
21
|
+
}, import("react").Dispatch<{
|
|
22
|
+
type: string;
|
|
23
|
+
payload?: Partial<IState> | undefined;
|
|
24
|
+
}>];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
/* eslint-disable no-case-declarations */
|
|
3
|
+
import { useReducer, useCallback } from 'react';
|
|
4
|
+
import { ERhythm } from '../../types/rhythms';
|
|
5
|
+
|
|
6
|
+
// 默认值
|
|
7
|
+
export const useRhythmReducer = init => {
|
|
8
|
+
const rhythmReducer = useCallback((state, action) => {
|
|
9
|
+
const oldState = _objectSpread({}, state);
|
|
10
|
+
switch (action.type) {
|
|
11
|
+
case ERhythm.UPDATE_LOCAL_MESSAGE:
|
|
12
|
+
return _objectSpread(_objectSpread({}, oldState), {}, {
|
|
13
|
+
localMessage: action.payload
|
|
14
|
+
});
|
|
15
|
+
case ERhythm.UPDATE_RHYTHMS:
|
|
16
|
+
return _objectSpread(_objectSpread({}, oldState), {}, {
|
|
17
|
+
rhythms: action.payload
|
|
18
|
+
});
|
|
19
|
+
case ERhythm.UPDATE_DP:
|
|
20
|
+
return _objectSpread(_objectSpread({}, oldState), {}, {
|
|
21
|
+
dpState: _objectSpread(_objectSpread({}, oldState.dpState), action.payload)
|
|
22
|
+
});
|
|
23
|
+
case ERhythm.UPDATE_RHYTHMS_MESSAGE:
|
|
24
|
+
return _objectSpread(_objectSpread({}, oldState), {}, {
|
|
25
|
+
rhythmsMessage: action.payload
|
|
26
|
+
});
|
|
27
|
+
case ERhythm.UPDATE_UI:
|
|
28
|
+
return _objectSpread(_objectSpread({}, oldState), action.payload);
|
|
29
|
+
case ERhythm.INIT_SYSTEM_INFO:
|
|
30
|
+
return _objectSpread(_objectSpread({}, oldState), {}, {
|
|
31
|
+
systemInfo: action.payload
|
|
32
|
+
});
|
|
33
|
+
default:
|
|
34
|
+
return state;
|
|
35
|
+
}
|
|
36
|
+
}, []);
|
|
37
|
+
return useReducer(rhythmReducer, init);
|
|
38
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const updateCommonFlatTimerList: (data: any) => any;
|
|
2
|
+
export declare const updateCommonFoldTimerList: (data: any) => any;
|
|
3
|
+
export declare const updateRecycleList: (data: any) => any;
|
|
4
|
+
export declare const updateRandomList: (data: any) => any;
|
|
5
|
+
export declare const updateRhythmList: (data: any) => any;
|
|
6
|
+
export declare const updateSleepList: (data: any) => any;
|
|
7
|
+
export declare const updateWakeupList: (data: any) => any;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { scheduleLogger as ScheduleLogger } from '../../utils/ScheduleLogger';
|
|
2
|
+
import { EScheduleActions } from './type';
|
|
3
|
+
export const updateCommonFlatTimerList = data => {
|
|
4
|
+
ScheduleLogger.debug(`action ${EScheduleActions.UPDATE_COMMON_FLAT_TIMER_LIST}`, data);
|
|
5
|
+
return {
|
|
6
|
+
type: EScheduleActions.UPDATE_COMMON_FLAT_TIMER_LIST,
|
|
7
|
+
payload: data
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export const updateCommonFoldTimerList = data => {
|
|
11
|
+
ScheduleLogger.debug(`action ${EScheduleActions.UPDATE_COMMON_FOLD_TIMER_LIST}`, data);
|
|
12
|
+
return {
|
|
13
|
+
type: EScheduleActions.UPDATE_COMMON_FOLD_TIMER_LIST,
|
|
14
|
+
payload: data
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export const updateRecycleList = data => {
|
|
18
|
+
ScheduleLogger.debug(`action ${EScheduleActions.UPDATE_RECYCLE_LIST}`, data);
|
|
19
|
+
return {
|
|
20
|
+
type: EScheduleActions.UPDATE_RECYCLE_LIST,
|
|
21
|
+
payload: data
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export const updateRandomList = data => {
|
|
25
|
+
ScheduleLogger.debug(`action ${EScheduleActions.UPDATE_RANDOM_LIST}`, data);
|
|
26
|
+
return {
|
|
27
|
+
type: EScheduleActions.UPDATE_RANDOM_LIST,
|
|
28
|
+
payload: data
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export const updateRhythmList = data => {
|
|
32
|
+
ScheduleLogger.debug(`action ${EScheduleActions.UPDATE_RHYTHM_LIST}`, data);
|
|
33
|
+
return {
|
|
34
|
+
type: EScheduleActions.UPDATE_RHYTHM_LIST,
|
|
35
|
+
payload: data
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export const updateSleepList = data => {
|
|
39
|
+
ScheduleLogger.debug(`action ${EScheduleActions.UPDATE_SLEEP_LIST}`, data);
|
|
40
|
+
return {
|
|
41
|
+
type: EScheduleActions.UPDATE_SLEEP_LIST,
|
|
42
|
+
payload: data
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export const updateWakeupList = data => {
|
|
46
|
+
ScheduleLogger.debug(`action ${EScheduleActions.UPDATE_WAKEUP_LIST}`, data);
|
|
47
|
+
return {
|
|
48
|
+
type: EScheduleActions.UPDATE_WAKEUP_LIST,
|
|
49
|
+
payload: data
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IState, IContext } from './type';
|
|
3
|
+
export declare const ScheduleContext: React.Context<IContext>;
|
|
4
|
+
export declare const getScheduleState: () => IState;
|
|
5
|
+
export declare const ContextProviderSchedule: React.FC;
|
|
6
|
+
export declare const useScheduleContext: () => IContext;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
import { useScheduleReducer } from './reducer';
|
|
4
|
+
import { updateCommonFlatTimerList, updateCommonFoldTimerList, updateRecycleList, updateRandomList, updateRhythmList, updateSleepList, updateWakeupList } from './actions';
|
|
5
|
+
const defaultScheduleData = {
|
|
6
|
+
commonFlatTimerList: [],
|
|
7
|
+
commonFoldTimerList: [],
|
|
8
|
+
randomList: [],
|
|
9
|
+
// 随机定时
|
|
10
|
+
rhythmList: [],
|
|
11
|
+
// 生物节律列表
|
|
12
|
+
sleepList: [],
|
|
13
|
+
// 入睡列表
|
|
14
|
+
wakeupList: [],
|
|
15
|
+
// 唤醒列表
|
|
16
|
+
recycleList: [] // 循环定时列表
|
|
17
|
+
};
|
|
18
|
+
export const ScheduleContext = /*#__PURE__*/React.createContext({
|
|
19
|
+
state: defaultScheduleData,
|
|
20
|
+
dispatch: () => null
|
|
21
|
+
});
|
|
22
|
+
let _scheduleState = defaultScheduleData;
|
|
23
|
+
|
|
24
|
+
// 方便其他地方获取 context state 值
|
|
25
|
+
export const getScheduleState = () => {
|
|
26
|
+
return _scheduleState;
|
|
27
|
+
};
|
|
28
|
+
export const ContextProviderSchedule = _ref => {
|
|
29
|
+
let {
|
|
30
|
+
children
|
|
31
|
+
} = _ref;
|
|
32
|
+
const [state, dispatch] = useScheduleReducer(defaultScheduleData);
|
|
33
|
+
_scheduleState = _objectSpread(_objectSpread({}, _scheduleState), state);
|
|
34
|
+
return /*#__PURE__*/React.createElement(ScheduleContext.Provider, {
|
|
35
|
+
value: {
|
|
36
|
+
state,
|
|
37
|
+
dispatch,
|
|
38
|
+
actions: {
|
|
39
|
+
updateCommonFlatTimerList,
|
|
40
|
+
updateCommonFoldTimerList,
|
|
41
|
+
updateRecycleList,
|
|
42
|
+
updateRandomList,
|
|
43
|
+
updateRhythmList,
|
|
44
|
+
updateSleepList,
|
|
45
|
+
updateWakeupList
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, children);
|
|
49
|
+
};
|
|
50
|
+
export const useScheduleContext = () => {
|
|
51
|
+
return useContext(ScheduleContext);
|
|
52
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getScheduleState, ContextProviderSchedule, useScheduleContext } from './context';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getScheduleState, ContextProviderSchedule, useScheduleContext } from './context';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Dispatch } from 'react';
|
|
2
|
+
import { TTimerData } from '../../types';
|
|
3
|
+
type TTimerReducer = {
|
|
4
|
+
commonFlatTimerList: TTimerData[];
|
|
5
|
+
commonFoldTimerList: TTimerData[];
|
|
6
|
+
randomList: any[];
|
|
7
|
+
rhythmList: any[];
|
|
8
|
+
sleepList: any[];
|
|
9
|
+
wakeupList: any[];
|
|
10
|
+
recycleList: any[];
|
|
11
|
+
};
|
|
12
|
+
export declare const useScheduleReducer: (init?: TTimerReducer) => [TTimerReducer, Dispatch<{
|
|
13
|
+
type: string;
|
|
14
|
+
payload;
|
|
15
|
+
}>];
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
/* eslint-disable no-case-declarations */
|
|
3
|
+
import { useReducer, useCallback } from 'react';
|
|
4
|
+
import { cloneDeep } from 'lodash-es';
|
|
5
|
+
import { EScheduleActions } from './type';
|
|
6
|
+
import { scheduleLogger as ScheduleLogger } from '../../utils/ScheduleLogger';
|
|
7
|
+
|
|
8
|
+
// 计划 Reducer
|
|
9
|
+
|
|
10
|
+
export const useScheduleReducer = function () {
|
|
11
|
+
let init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
12
|
+
commonFlatTimerList: [],
|
|
13
|
+
commonFoldTimerList: [],
|
|
14
|
+
randomList: [],
|
|
15
|
+
// 随机定时
|
|
16
|
+
rhythmList: [],
|
|
17
|
+
// 生物节律列表
|
|
18
|
+
sleepList: [],
|
|
19
|
+
// 入睡列表
|
|
20
|
+
wakeupList: [],
|
|
21
|
+
// 唤醒列表
|
|
22
|
+
recycleList: [] // 循环定时列表
|
|
23
|
+
};
|
|
24
|
+
const reducer = useCallback((state, action) => {
|
|
25
|
+
ScheduleLogger.debug('useScheduleReducer RUN:', action.type);
|
|
26
|
+
switch (action.type) {
|
|
27
|
+
case EScheduleActions.UPDATE_COMMON_FLAT_TIMER_LIST:
|
|
28
|
+
const _newData = cloneDeep(state.commonFlatTimerList);
|
|
29
|
+
const index = _newData.findIndex(i => {
|
|
30
|
+
var _action$payload;
|
|
31
|
+
return i.id === ((_action$payload = action.payload) === null || _action$payload === void 0 ? void 0 : _action$payload.id);
|
|
32
|
+
});
|
|
33
|
+
index > -1 && _newData.splice(index, 1);
|
|
34
|
+
// 添加
|
|
35
|
+
_newData.push(action.payload);
|
|
36
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
37
|
+
commonFlatTimerList: [..._newData]
|
|
38
|
+
});
|
|
39
|
+
case EScheduleActions.UPDATE_COMMON_FOLD_TIMER_LIST:
|
|
40
|
+
const commonFoldTimerList = cloneDeep(state.commonFoldTimerList);
|
|
41
|
+
const commonFoldTimerIndex = commonFoldTimerList.findIndex(i => {
|
|
42
|
+
var _action$payload2;
|
|
43
|
+
return i.id === ((_action$payload2 = action.payload) === null || _action$payload2 === void 0 ? void 0 : _action$payload2.id);
|
|
44
|
+
});
|
|
45
|
+
commonFoldTimerIndex > -1 && commonFoldTimerList.splice(commonFoldTimerIndex, 1);
|
|
46
|
+
// 添加
|
|
47
|
+
commonFoldTimerList.push(action.payload);
|
|
48
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
49
|
+
commonFoldTimerList: [...commonFoldTimerList]
|
|
50
|
+
});
|
|
51
|
+
case EScheduleActions.UPDATE_RANDOM_LIST:
|
|
52
|
+
const randomList = cloneDeep(state.randomList);
|
|
53
|
+
const randomIndex = randomList.findIndex(i => {
|
|
54
|
+
var _action$payload3;
|
|
55
|
+
return i.id === ((_action$payload3 = action.payload) === null || _action$payload3 === void 0 ? void 0 : _action$payload3.id);
|
|
56
|
+
});
|
|
57
|
+
randomIndex > -1 && randomList.splice(randomIndex, 1);
|
|
58
|
+
// 添加
|
|
59
|
+
randomList.push(action.payload);
|
|
60
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
61
|
+
randomList: [...randomList]
|
|
62
|
+
});
|
|
63
|
+
case EScheduleActions.UPDATE_RECYCLE_LIST:
|
|
64
|
+
const recycleList = cloneDeep(state.recycleList);
|
|
65
|
+
const recycleIndex = recycleList.findIndex(i => {
|
|
66
|
+
var _action$payload4;
|
|
67
|
+
return i.id === ((_action$payload4 = action.payload) === null || _action$payload4 === void 0 ? void 0 : _action$payload4.id);
|
|
68
|
+
});
|
|
69
|
+
recycleIndex > -1 && recycleList.splice(recycleIndex, 1);
|
|
70
|
+
// 添加
|
|
71
|
+
recycleList.push(action.payload);
|
|
72
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
73
|
+
recycleList: [...recycleList]
|
|
74
|
+
});
|
|
75
|
+
case EScheduleActions.UPDATE_SLEEP_LIST:
|
|
76
|
+
const sleepList = cloneDeep(state.sleepList);
|
|
77
|
+
const sleepIndex = sleepList.findIndex(i => {
|
|
78
|
+
var _action$payload5;
|
|
79
|
+
return i.id === ((_action$payload5 = action.payload) === null || _action$payload5 === void 0 ? void 0 : _action$payload5.id);
|
|
80
|
+
});
|
|
81
|
+
sleepIndex > -1 && sleepList.splice(sleepIndex, 1);
|
|
82
|
+
// 添加
|
|
83
|
+
sleepList.push(action.payload);
|
|
84
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
85
|
+
sleepList: [...sleepList]
|
|
86
|
+
});
|
|
87
|
+
case EScheduleActions.UPDATE_WAKEUP_LIST:
|
|
88
|
+
const wakeupList = cloneDeep(state.wakeupList);
|
|
89
|
+
const wakeupIndex = wakeupList.findIndex(i => {
|
|
90
|
+
var _action$payload6;
|
|
91
|
+
return i.id === ((_action$payload6 = action.payload) === null || _action$payload6 === void 0 ? void 0 : _action$payload6.id);
|
|
92
|
+
});
|
|
93
|
+
wakeupIndex > -1 && wakeupList.splice(wakeupIndex, 1);
|
|
94
|
+
// 添加
|
|
95
|
+
wakeupList.push(action.payload);
|
|
96
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
97
|
+
wakeupList: [...wakeupList]
|
|
98
|
+
});
|
|
99
|
+
default:
|
|
100
|
+
return state;
|
|
101
|
+
}
|
|
102
|
+
}, []);
|
|
103
|
+
return useReducer(reducer, init);
|
|
104
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Dispatch } from 'react';
|
|
2
|
+
export declare enum EScheduleActions {
|
|
3
|
+
UPDATE_COMMON_FOLD_TIMER_LIST = "UPDATE_COMMON_FOLD_TIMER_LIST",
|
|
4
|
+
UPDATE_COMMON_FLAT_TIMER_LIST = "UPDATE_COMMON_FLAT_TIMER_LIST",
|
|
5
|
+
UPDATE_TIMER_LIST = "UPDATE_TIMER_LIST",
|
|
6
|
+
UPDATE_RECYCLE_LIST = "UPDATE_RECYCLE_LIST",
|
|
7
|
+
UPDATE_RANDOM_LIST = "UPDATE_RANDOM_LIST",
|
|
8
|
+
UPDATE_RHYTHM_LIST = "UPDATE_RHYTHM_LIST",
|
|
9
|
+
UPDATE_SLEEP_LIST = "UPDATE_SLEEP_LIST",
|
|
10
|
+
UPDATE_WAKEUP_LIST = "UPDATE_WAKEUP_LIST"
|
|
11
|
+
}
|
|
12
|
+
export interface IState {
|
|
13
|
+
commonFlatTimerList: any[];
|
|
14
|
+
commonFoldTimerList: any[];
|
|
15
|
+
randomList: any[];
|
|
16
|
+
rhythmList: any[];
|
|
17
|
+
sleepList: any[];
|
|
18
|
+
wakeupList: any[];
|
|
19
|
+
recycleList: any[];
|
|
20
|
+
}
|
|
21
|
+
export interface IScheduleReturn {
|
|
22
|
+
type: any;
|
|
23
|
+
payload: any;
|
|
24
|
+
}
|
|
25
|
+
export interface IContext {
|
|
26
|
+
state: IState;
|
|
27
|
+
dispatch: Dispatch<{
|
|
28
|
+
type: string;
|
|
29
|
+
payload?: Partial<IState>;
|
|
30
|
+
}>;
|
|
31
|
+
actions?: TActions;
|
|
32
|
+
}
|
|
33
|
+
export type TActions = {
|
|
34
|
+
updateCommonFlatTimerList: (data: any) => any;
|
|
35
|
+
updateCommonFoldTimerList: (data: any) => any;
|
|
36
|
+
updateRecycleList: (data: any) => any;
|
|
37
|
+
updateRandomList: (data: any) => any;
|
|
38
|
+
updateRhythmList: (data: any) => any;
|
|
39
|
+
updateSleepList: (data: any) => any;
|
|
40
|
+
updateWakeupList: (data: any) => any;
|
|
41
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export let EScheduleActions = /*#__PURE__*/function (EScheduleActions) {
|
|
2
|
+
EScheduleActions["UPDATE_COMMON_FOLD_TIMER_LIST"] = "UPDATE_COMMON_FOLD_TIMER_LIST";
|
|
3
|
+
EScheduleActions["UPDATE_COMMON_FLAT_TIMER_LIST"] = "UPDATE_COMMON_FLAT_TIMER_LIST";
|
|
4
|
+
EScheduleActions["UPDATE_TIMER_LIST"] = "UPDATE_TIMER_LIST";
|
|
5
|
+
EScheduleActions["UPDATE_RECYCLE_LIST"] = "UPDATE_RECYCLE_LIST";
|
|
6
|
+
EScheduleActions["UPDATE_RANDOM_LIST"] = "UPDATE_RANDOM_LIST";
|
|
7
|
+
EScheduleActions["UPDATE_RHYTHM_LIST"] = "UPDATE_RHYTHM_LIST";
|
|
8
|
+
EScheduleActions["UPDATE_SLEEP_LIST"] = "UPDATE_SLEEP_LIST";
|
|
9
|
+
EScheduleActions["UPDATE_WAKEUP_LIST"] = "UPDATE_WAKEUP_LIST";
|
|
10
|
+
return EScheduleActions;
|
|
11
|
+
}({});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ILocalTimerReturn, ICloudTimerReturn } from './type';
|
|
2
|
+
import { TTimerData, TTimerDataAdd, TTimerDataUpdate } from '../../types';
|
|
3
|
+
export declare const addRtcTimer: (data: TTimerDataAdd) => ILocalTimerReturn;
|
|
4
|
+
export declare const removeRtcTimer: (timerId: string) => ILocalTimerReturn;
|
|
5
|
+
export declare const updateRtcTimer: (data: TTimerDataUpdate) => ILocalTimerReturn;
|
|
6
|
+
export declare const closeAllRtcTimer: (timerIdList: string[]) => ILocalTimerReturn;
|
|
7
|
+
export declare const flushRtcTimerList: (data: TTimerData[]) => ILocalTimerReturn;
|
|
8
|
+
export declare const flushCloudTimerList: (data: TTimerData[]) => ICloudTimerReturn;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ECouldTimer, ERtcTimer } from './type';
|
|
2
|
+
import { scheduleLogger as ScheduleLogger } from '../../utils/ScheduleLogger';
|
|
3
|
+
export const addRtcTimer = data => {
|
|
4
|
+
ScheduleLogger.debug('action ADD_RTC_TIMER', data);
|
|
5
|
+
return {
|
|
6
|
+
type: ERtcTimer.ADD_RTC_TIMER,
|
|
7
|
+
payload: data
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// 删除本地定时器
|
|
12
|
+
export const removeRtcTimer = timerId => {
|
|
13
|
+
ScheduleLogger.debug('action REMOVE_RTC_TIMER', timerId);
|
|
14
|
+
return {
|
|
15
|
+
type: ERtcTimer.REMOVE_RTC_TIMER,
|
|
16
|
+
payload: timerId
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export const updateRtcTimer = data => {
|
|
20
|
+
ScheduleLogger.debug('action UPDATE_RTC_TIMER', data);
|
|
21
|
+
return {
|
|
22
|
+
type: ERtcTimer.UPDATE_RTC_TIMER,
|
|
23
|
+
payload: data
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// 关闭所有的本地定时
|
|
28
|
+
export const closeAllRtcTimer = timerIdList => {
|
|
29
|
+
ScheduleLogger.debug('action CLOSE_ALL_RTC_TIMER', timerIdList);
|
|
30
|
+
return {
|
|
31
|
+
type: ERtcTimer.CLOSE_ALL_RTC_TIMER,
|
|
32
|
+
payload: timerIdList
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// 刷新本地定时器列表
|
|
37
|
+
export const flushRtcTimerList = data => {
|
|
38
|
+
ScheduleLogger.debug('action FLUSH_RTC_TIMER_LIST', data);
|
|
39
|
+
return {
|
|
40
|
+
type: ERtcTimer.FLUSH_RTC_TIMER_LIST,
|
|
41
|
+
payload: data
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// 刷新云定时器列表
|
|
46
|
+
export const flushCloudTimerList = data => {
|
|
47
|
+
ScheduleLogger.debug('FLUSH_CLOUD_TIMER_LIST', data);
|
|
48
|
+
return {
|
|
49
|
+
type: ECouldTimer.FLUSH_CLOUD_TIMER_LIST,
|
|
50
|
+
payload: data
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IState, IContext, TActions } from './type';
|
|
3
|
+
export declare const TimerContext: React.Context<IContext>;
|
|
4
|
+
export declare const getTimerState: () => IState;
|
|
5
|
+
export declare const getTimerReducer: () => {
|
|
6
|
+
dispatch: React.Dispatch<any>;
|
|
7
|
+
actions: TActions;
|
|
8
|
+
};
|
|
9
|
+
export declare const ContextProviderTimer: React.FC;
|
|
10
|
+
export declare const useTimerContext: () => IContext;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
import { useTimerReducer } from './reducer';
|
|
4
|
+
import { addRtcTimer, removeRtcTimer, updateRtcTimer, closeAllRtcTimer, flushRtcTimerList, flushCloudTimerList } from './actions';
|
|
5
|
+
const defaultTimerData = {
|
|
6
|
+
rtcTimerList: [],
|
|
7
|
+
cloudTimerList: []
|
|
8
|
+
};
|
|
9
|
+
export const TimerContext = /*#__PURE__*/React.createContext({
|
|
10
|
+
state: defaultTimerData,
|
|
11
|
+
dispatch: () => null
|
|
12
|
+
});
|
|
13
|
+
let _timerState = defaultTimerData;
|
|
14
|
+
|
|
15
|
+
// 方便其他地方获取 context state 值
|
|
16
|
+
export const getTimerState = () => {
|
|
17
|
+
return _timerState;
|
|
18
|
+
};
|
|
19
|
+
let _dispatch = () => null;
|
|
20
|
+
let _actions = {};
|
|
21
|
+
export const getTimerReducer = () => {
|
|
22
|
+
return {
|
|
23
|
+
dispatch: _dispatch,
|
|
24
|
+
actions: _actions
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export const ContextProviderTimer = _ref => {
|
|
28
|
+
let {
|
|
29
|
+
children
|
|
30
|
+
} = _ref;
|
|
31
|
+
const actions = {
|
|
32
|
+
addRtcTimer,
|
|
33
|
+
removeRtcTimer,
|
|
34
|
+
updateRtcTimer,
|
|
35
|
+
closeAllRtcTimer,
|
|
36
|
+
flushRtcTimerList,
|
|
37
|
+
flushCloudTimerList
|
|
38
|
+
};
|
|
39
|
+
const [state, dispatch] = useTimerReducer(defaultTimerData);
|
|
40
|
+
_timerState = _objectSpread(_objectSpread({}, _timerState), state);
|
|
41
|
+
_actions = actions;
|
|
42
|
+
_dispatch = dispatch;
|
|
43
|
+
return /*#__PURE__*/React.createElement(TimerContext.Provider, {
|
|
44
|
+
value: {
|
|
45
|
+
state,
|
|
46
|
+
dispatch,
|
|
47
|
+
actions
|
|
48
|
+
}
|
|
49
|
+
}, children);
|
|
50
|
+
};
|
|
51
|
+
export const useTimerContext = () => {
|
|
52
|
+
return useContext(TimerContext);
|
|
53
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getTimerState, ContextProviderTimer, useTimerContext, getTimerReducer } from './context';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getTimerState, ContextProviderTimer, useTimerContext, getTimerReducer } from './context';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Dispatch } from 'react';
|
|
2
|
+
import { ICloudTimerReturn, ITimerReturn, ILocalTimerReturn } from './type';
|
|
3
|
+
import { TTimerData } from '../../types';
|
|
4
|
+
type TTimerReducer = {
|
|
5
|
+
rtcTimerList: TTimerData[];
|
|
6
|
+
cloudTimerList: TTimerData[];
|
|
7
|
+
};
|
|
8
|
+
export declare const useTimerReducer: (init: TTimerReducer) => [
|
|
9
|
+
TTimerReducer,
|
|
10
|
+
Dispatch<{
|
|
11
|
+
type: string;
|
|
12
|
+
payload?: ICloudTimerReturn | ILocalTimerReturn | ITimerReturn;
|
|
13
|
+
}>
|
|
14
|
+
];
|
|
15
|
+
export {};
|