Skip to content

Commit f70cea8

Browse files
committed
separated getComponentByIndex for Class vs Hooks
1 parent 0453165 commit f70cea8

File tree

2 files changed

+11
-59
lines changed

2 files changed

+11
-59
lines changed

src/backend/masterState.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export default {
2323
return index - 1;
2424
},
2525
getRecordByIndex: (inputIndex: number): HookStateItem => componentActionsRecord[inputIndex],
26-
// getComponentByIndex: (inputIndex: number): any => (componentActionsRecord[inputIndex]
27-
// ? componentActionsRecord[inputIndex].component
28-
// : undefined),
29-
getComponentByIndex: (inputIndex: Array<number> = []): any => {
26+
getComponentByIndex: (inputIndex: number): any => (componentActionsRecord[inputIndex]
27+
? componentActionsRecord[inputIndex].component
28+
: undefined),
29+
getComponentByIndexHooks: (inputIndex: Array<number> = []): any => {
3030
const multiDispatch = [];
3131
for (let i = 0; i < inputIndex.length; i++) {
3232
if (componentActionsRecord[inputIndex[i]]) multiDispatch.push(componentActionsRecord[inputIndex[i]].component);

src/backend/timeJump.ts

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -65,54 +65,18 @@ export default (origin, mode) => {
6565
}
6666
});
6767

68-
// Check for hooks state and set it with dispatch()
69-
// if (target.state && target.state.hooksState) {
70-
// target.state.hooksState.forEach(hook => {
71-
// const hooksComponent = componentActionsRecord.getComponentByIndex(
72-
// target.componentData.hooksIndex,
73-
// );
74-
// // console.log('hooksComponent', hooksComponent);
75-
// const hookState = Object.values(hook);
76-
// if (hooksComponent && hooksComponent.dispatch) {
77-
// if (Array.isArray(hookState[0]) && hookState[0].length > 0 || !Array.isArray(hookState[0])) {
78-
// hooksComponent.dispatch(hookState[0]);
79-
// }
80-
// }
81-
// });
82-
// }
83-
84-
// attempt 2
85-
// if (target.state && target.state.hooksState) {
86-
// console.log('target.state.hooksState', target.state.hooksState);
87-
// // console.log('target.componentData.hooksIndex', target.componentData.hooksIndex);
88-
// // console.log('componentActionsRecord', componentActionsRecord);
89-
// const hooksComponent = componentActionsRecord.getComponentByIndex(
90-
// target.componentData.hooksIndex,
91-
// // 13,
92-
// // whatever we pass into here is the hook that is being updated
93-
// );
94-
// // console.log('hooksComponent', hooksComponent);
95-
// const hookState = Object.values(target.state.hooksState[0]);
96-
// // console.log('hookState', hookState);
97-
// if (hooksComponent && hooksComponent.dispatch) {
98-
// if (Array.isArray(hookState[0]) && hookState[0].length > 0 || !Array.isArray(hookState[0])) {
99-
// hooksComponent.dispatch(hookState[0]);
100-
// }
101-
// }
102-
// }
103-
10468
// multiple dispatch check
10569
if (target.state && target.state.hooksState) {
106-
const numState = target.state.hooksState.length;
70+
const currState = target.state.hooksState;
10771
const numArr: Array<number> = [];
10872
let counter = 1;
109-
while (counter < numState + 1) {
110-
numArr.push(target.componentData.hooksIndex - numState + counter);
73+
while (counter < currState.length + 1) {
74+
numArr.push(target.componentData.hooksIndex - currState.length + counter);
11175
counter += 1;
11276
}
113-
const hooksComponent = componentActionsRecord.getComponentByIndex(numArr);
114-
for (let i = 0; i < target.state.hooksState.length; i += 1) {
115-
hooksComponent[i].dispatch(Object.values(target.state.hooksState[i])[0]);
77+
const hooksComponent = componentActionsRecord.getComponentByIndexHooks(numArr);
78+
for (let i = 0; i < currState.length; i += 1) {
79+
hooksComponent[i].dispatch(Object.values(currState[i])[0]);
11680
}
11781
}
11882
}
@@ -126,16 +90,4 @@ export default (origin, mode) => {
12690
mode.jumping = false;
12791
}, 100);
12892
};
129-
};
130-
131-
132-
133-
134-
// // if (target.state.hooksState.length > 1) {
135-
// for (let i = 0; i < target.state.hooksState.length; i += 1) {
136-
// // if (Array.isArray(Object.values(target.state.hooksState[i]))) {
137-
// // hooksComponent[i].dispatch(Object.values(target.state.hooksState[i])[0]);
138-
// // } else {
139-
// hooksComponent[i].dispatch(Object.values(target.state.hooksState[i])[0]);
140-
// // }
141-
// // }
93+
};

0 commit comments

Comments
 (0)