Sorry for the vague question.
Got a store which I filled with data. As far as I can see the data that I put in is correct. I've used many breakpoints.
My site contains 2 +page files, so let's call them page 1 and page 2.
I set the store on page 1 like this inside an async method:
async function register() {
connection.on('ReceiveLlmResponse', (_, fileName, contentType, fileContent, oldFileContent) => {
let diffDataStructure = CreateDiffDataStructure(oldFileContent, fileContent, { ignoreWhitespace: true });
let calculated = calculateLineNumbers(diffDataStructure);
diffStore.update((current) => {
const diff = {
id: current ? current.length : 0,
fileName: fileName,
diffs: calculated
};
console.info('info', current);
if (current) {
console.info('went into place where should not come', [...current, diff])
return [...current, diff];
}
console.info('retyurned correctly', [diff])
return [diff];
});
}
In those logs, the data is correct at every step. Also correct using the debugger. Then it goes to the next page:
It first stops here:
diffStore.subscribe((value) => {
if (value === null) return;
diffDataD = value; <<< here
});
And the data in value is correct. Then it goes to here:
<div class="column-container">
{#if diffDataD && Array.isArray(diffDataD)} <<<< breakpoint over here
{console.log(diffDataD)}
<div class="code maxxed">
{#each diffDataD as diffItem}
<h2>Old: {diffItem.fileName}</h2>
And for some reason the data inside diffDataD looks nothing like the data that I put into the store.
So here's an example of correct data:
0: diffs: (13) [{...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}]
fileName: "admin.controller.ts"
id: 0
And her an exampl of the wrong data which makes my code break (added as .txt file):
diffDataD: [
null,
null,
[{...}], <<< this array of objects is my correct data
undefined,
(diffId, diffItemId, index, old) => {...},
function handleTextEdit(diffId, diffItemId, index, event) {...},
function handleTextBlur(diffId, diffItemId, index, event) {...},
(diff, diffItem, oldIndex) => {...},
(diff, diffItem, oldIndex) => {...},
event => handleDelete(event),
event => handleDelete(event),
function textarea_input_handler(each_value_6, mergedIndex) {...},
(diff, diffItem, mergedIndex, event) => {...},
(diff, diffItem, mergedIndex, event) => {...},
(diff, diffItem, newIndex) => {...},
(diff, diffItem, newIndex) => {...}
]
I'm lost. Why does this happen. I don't understand at what point this goes wrong.
I put logs at every step in my code. I used a debugger. I disabled parts of the code.