You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// and if our input object's children property is non-empty, go through each children object from our input object and determine, if the object being iterated on either has a stateless state or has a children array with a non-zero amount of objects. Objects that fulfill the above that need to be cleaned through statelessCleaning. Those that are cleaned through this process are then pushed to the new object's children array.
// function determines whether delta has resulted in a changedState. Function would return an empty array if there were no changes to state and an array of objects that changed state.
95
-
if(!delta.children&&!delta.state){
96
-
// if delta doesn't have a children property or a state property
changedState.push(delta.state);// and push stateful delta objects to changedState
103
-
}
104
-
105
-
if(!delta.children){
106
-
// if the delta doesn't have any children
107
-
returnchangedState;// return the changedState array with any and all stateful delta objects.
89
+
changedState.push(delta.state);
108
90
}
109
-
91
+
if(!delta.children)returnchangedState;
110
92
Object.keys(delta.children).forEach((child)=>{
111
-
// but if the delta object did have children, we iterate through each child object
112
-
// if (isNaN(child) === false) {
113
-
changedState.push(...findStateChangeObj(delta.children[child]));// recursively call this function on each child object. Push every 'stateful' child into the changedState array.
if(index===0)return'';// Return empty string for initial state
108
+
try{
109
+
constdelta=diff(
110
+
statelessCleaning(snapshots[index-1]),
111
+
statelessCleaning(snapshots[index]),
112
+
);
113
+
114
+
if(!delta)return'No state changes';
121
115
122
-
constdelta=diff(
123
-
// 'diff' function from 'jsondiffpatch' returns the difference in state between the (snapshot that occurred before the indexed snapshot) and the (indexed snapshot).
124
-
statelessCleaning(snapshots[index-1]),
125
-
statelessCleaning(snapshots[index]),
126
-
);
127
-
constchangedState=findStateChangeObj(delta);// determines if delta had any stateful changes
128
-
consthtml=formatters.html.format(changedState[0]);// formats the difference into html string
129
-
returnhtml;// return html string
116
+
constchangedState=findStateChangeObj(delta);
117
+
returnchangedState.length>0 ? formatters.html.format(changedState[0]) : 'No state changes';
0 commit comments