Skip to content

Commit 9d9bd36

Browse files
committed
changed hooksState snapshot format
1 parent d62fa75 commit 9d9bd36

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

src/app/containers/MainContainer.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ function MainContainer() {
8484
// if viewIndex is -1, then use the sliderIndex instead
8585
const snapshotView = viewIndex === -1 ? snapshots[sliderIndex] : snapshots[viewIndex];
8686
// gabi :: cleannign hierarchy and snapshotView from stateless data
87-
const statelessCleanning = (obj:{name?:string; componentData?:object; state?:object|string;stateSnaphot?:object; children?:any[]}) => {
87+
const statelessCleanning = (
88+
obj:{
89+
name?:string;
90+
componentData?:object;
91+
state?:{hooksState?: any | {componentData?: any}[]} | string;
92+
stateSnaphot?:object;
93+
children?:any[];
94+
}) => {
8895
const newObj = { ...obj };
8996
if (newObj.name === 'nameless') {
9097
delete newObj.name;
@@ -95,6 +102,14 @@ function MainContainer() {
95102
if (newObj.state === 'stateless') {
96103
delete newObj.state;
97104
}
105+
if (newObj.state && newObj.state.hooksState) {
106+
if (Array.isArray(newObj.state.hooksState)) {
107+
newObj.state.hooksState.forEach(s => {
108+
delete s.componentData;
109+
});
110+
}
111+
}
112+
98113
if (newObj.stateSnaphot) {
99114
newObj.stateSnaphot = statelessCleanning(obj.stateSnaphot);
100115
}

src/app/reducers/mainReducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default (state, action) => produce(state, draft => {
1818
// eslint-disable-next-line consistent-return
1919
const findName = (index, obj) => {
2020
// eslint-disable-next-line eqeqeq
21-
if (obj.index == index) {
21+
if (obj && obj.index == index) {
2222
return obj.name;
2323
}
2424

src/backend/linkFiber.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
107107
treeBaseDuration,
108108
} = currentFiber;
109109

110-
let newState: any;
110+
let newState: any = {};
111111
let componentData: ComponentData = {};
112112
let componentFound = false;
113113

@@ -133,11 +133,15 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
133133
hooksStates.forEach((state, i) => {
134134
hooksIndex = componentActionsRecord.saveNew(state.state, state.component);
135135
if (newState && newState.hooksState) {
136-
newState.hooksState.push([{ [hooksNames[i]]: state.state }, hooksIndex]);
136+
newState.hooksState.push({ [hooksNames[i]]: state.state, componentData: { index: hooksIndex } });
137+
// newState.hooksState.push([{ [hooksNames[i]]: state.state }, hooksIndex]);
137138
} else if (newState) {
138-
newState.hooksState = [{ [hooksNames[i]]: state.state }, hooksIndex];
139+
newState.hooksState = [{ [hooksNames[i]]: state.state, componentData: { index: hooksIndex } }];
140+
// newState.hooksState = [{ [hooksNames[i]]: state.state }, hooksIndex];
139141
} else {
140-
newState = { hooksState: [{ [hooksNames[i]]: state.state }, hooksIndex] };
142+
// newState = { hooksState: [{ [hooksNames[i]]: state.state }, hooksIndex] };
143+
newState = { hooksState: [] };
144+
newState.hooksState.push({ [hooksNames[i]]: state.state, componentData: { index: hooksIndex } });
141145
}
142146
componentFound = true;
143147
});

src/backend/timeJump.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default (origin, mode) => {
2828
// Set the state of the origin tree if the component is stateful
2929

3030
if (!target) return;
31+
3132
if (target.state === 'stateless') target.children.forEach(child => jump(child));
3233
const component = componentActionsRecord.getComponentByIndex(target.componentData.index);
3334
if (component && component.setState) {
@@ -43,15 +44,23 @@ export default (origin, mode) => {
4344
}
4445

4546
// Check for hooks state and set it with dispatch()
46-
if (target.state.hooksState) {
47-
const hooksComponent = componentActionsRecord.getComponentByIndex(target.state.hooksState[1]);
48-
// const [hooksState] = [target.state.hooksState];
49-
const hooksState = Object.values(target.state.hooksState[0])[0];
50-
if (hooksComponent && hooksComponent.dispatch) {
51-
// hooksComponent.dispatch(Object.values(target.state.hooksState[0])[0]);
52-
hooksComponent.dispatch(hooksState);
53-
}
54-
target.children.forEach(child => jump(child));
47+
if (target.state && target.state.hooksState) {
48+
console.log('SNAPSHOT TARGET: ', target);
49+
// const hooksComponent = componentActionsRecord.getComponentByIndex(target.state.hooksState[1]);
50+
target.state.hooksState.forEach(hook => {
51+
console.log('HOOK IS:', JSON.stringify(hook));
52+
if (!hook.componentData) return;
53+
const hooksComponent = componentActionsRecord.getComponentByIndex(hook.componentData.index);
54+
// const [hooksState] = [target.state.hooksState];
55+
delete hook.componentData;
56+
const hooksState = Object.values(hook);
57+
if (hooksComponent && hooksComponent.dispatch) {
58+
// hooksComponent.dispatch(Object.values(target.state.hooksState[0])[0]);
59+
hooksComponent.dispatch(hooksState);
60+
}
61+
});
62+
//target.children.forEach(child => jump(child));
63+
5564
}
5665

5766
target.children.forEach(child => {

0 commit comments

Comments
 (0)