@mchp-mcc/clock-16bit-driver 1.0.1 → 1.0.2
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/Changelog.md +7 -0
- package/Readme.md +7 -2
- package/output/creator.js +3328 -3
- package/output/creator.js.map +1 -1
- package/output/index.html +25 -0
- package/output/nullPrototype.json +11 -1
- package/output/processor.js +6096 -16
- package/output/processor.js.map +1 -1
- package/output/reducer.js +17774 -0
- package/output/reducer.js.map +1 -0
- package/output/resources/help-icon.png +0 -0
- package/output/resources/loading-status.gif +0 -0
- package/package.json +34 -10
- package/src/App.tsx +54 -0
- package/src/DerivedData.tsx +219 -13
- package/src/actions.ts +22 -0
- package/src/catalog.json +25 -0
- package/src/index.tsx +48 -0
- package/src/moduleConfig.json +13 -3
- package/src/reducer.tsx +94 -0
package/src/reducer.tsx
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
import { State } from "../generated_module/src/types/State";
|
2
|
+
import { Actions } from "@microchip/scf-autoview/lib/simpleForm/actions";
|
3
|
+
import * as Auto from "@microchip/scf-autoview-impl/src/lib/reducer/reducer";
|
4
|
+
import { ClockAction, ClockActionPayload, ClockActions } from "./actions";
|
5
|
+
import {
|
6
|
+
COMPONENT_AUX_CLOCK_INPUT_FREQUENCY,
|
7
|
+
COMPONENT_MAIN_CLOCK_INPUT_FREQUENCY,
|
8
|
+
COMPONENT_REQUESTED_AUX_CLOCK_OUTPUT_FREQUENCY,
|
9
|
+
COMPONENT_REQUESTED_REF_CLOCK_OUTPUT_FREQUENCY,
|
10
|
+
COMPONENT_REQUESTED_SYSTEM_FREQUENCY,
|
11
|
+
} from "./DerivedData";
|
12
|
+
|
13
|
+
export interface MyState extends Auto.FormState {
|
14
|
+
[key: string]: any;
|
15
|
+
}
|
16
|
+
|
17
|
+
export const reduce = (state: State, action: any): State => {
|
18
|
+
switch (action.type) {
|
19
|
+
case Actions.SUBMIT_FORM:
|
20
|
+
return Auto.reduce(state, action);
|
21
|
+
case ClockActions.FORCE_UPDATE:
|
22
|
+
return clockReduce(state, action);
|
23
|
+
default:
|
24
|
+
return state;
|
25
|
+
}
|
26
|
+
};
|
27
|
+
|
28
|
+
export const clockReduce = (state: State, action: any): State => {
|
29
|
+
switch (action.type) {
|
30
|
+
case ClockActions.FORCE_UPDATE:
|
31
|
+
return updateClockUI(state, action);
|
32
|
+
default:
|
33
|
+
return state;
|
34
|
+
}
|
35
|
+
};
|
36
|
+
|
37
|
+
const updateClockUI = (state: State, action: ClockAction): State => {
|
38
|
+
const payload = action.payload;
|
39
|
+
let componentName = "";
|
40
|
+
const componentPath = payload?.key?.split(".");
|
41
|
+
if (componentPath != undefined) {
|
42
|
+
componentName = componentPath[componentPath?.length - 1];
|
43
|
+
}
|
44
|
+
const typeCastedComponentValue = getTypeCastedComponentValue(componentName, payload);
|
45
|
+
const newState = getNewState(state, componentName, typeCastedComponentValue);
|
46
|
+
return newState;
|
47
|
+
};
|
48
|
+
|
49
|
+
const getTypeCastedComponentValue = (
|
50
|
+
componentName: string,
|
51
|
+
payload: ClockActionPayload | undefined,
|
52
|
+
): string | number | undefined => {
|
53
|
+
let componentValue: string | number | undefined;
|
54
|
+
if (
|
55
|
+
componentName === COMPONENT_MAIN_CLOCK_INPUT_FREQUENCY ||
|
56
|
+
componentName === COMPONENT_REQUESTED_SYSTEM_FREQUENCY ||
|
57
|
+
componentName === COMPONENT_AUX_CLOCK_INPUT_FREQUENCY ||
|
58
|
+
componentName === COMPONENT_REQUESTED_AUX_CLOCK_OUTPUT_FREQUENCY ||
|
59
|
+
componentName === COMPONENT_REQUESTED_REF_CLOCK_OUTPUT_FREQUENCY
|
60
|
+
) {
|
61
|
+
componentValue = Number(payload?.value);
|
62
|
+
} else {
|
63
|
+
componentValue = payload?.value;
|
64
|
+
}
|
65
|
+
return componentValue;
|
66
|
+
};
|
67
|
+
|
68
|
+
const getNewState = (
|
69
|
+
state: State,
|
70
|
+
componentName: string,
|
71
|
+
componentValue: string | number | undefined,
|
72
|
+
): State => {
|
73
|
+
for (const key in state) {
|
74
|
+
state[key] = updateValue(key, state[key], componentName, componentValue);
|
75
|
+
}
|
76
|
+
return state;
|
77
|
+
};
|
78
|
+
|
79
|
+
const updateValue = (
|
80
|
+
key: string,
|
81
|
+
existingValue: string | State,
|
82
|
+
componentName: string,
|
83
|
+
newValue: string | number | undefined,
|
84
|
+
): string | number | State => {
|
85
|
+
if (typeof existingValue == "object") {
|
86
|
+
return getNewState(existingValue, componentName, newValue);
|
87
|
+
} else {
|
88
|
+
if (key == componentName && newValue != undefined) {
|
89
|
+
return newValue;
|
90
|
+
} else {
|
91
|
+
return existingValue;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
};
|