I have a store:
export const [mainStore, setMainStore] = createStore<StoreType>({ countries: undefined });
of this type:
export type StoreType = {
countries?: FrontEndCountry[]
}
export interface FrontEndCountry {
id: string
name: string
type?: string | null
parentCountryId?: string | null
subtitle?: string | null
description?: string | null
countrySprites: FrontEndSprite[]
}
export interface FrontEndSprite {
lat: number
lng: number
z: number
scale: number
mapName: string
countryId: string
}
I'm trying to render only part of these countries, or rather their sprites. I filter them out and render them like this:
<For each={mainStore.countries?.filter(c => {
const countryIsExtra = !countryNames.includes(c.name);
const extraSelected = characters().includes("extra");
if (countryIsExtra && !extraSelected)
return false;
const countrySelected = characters().includes("countries");
if (!countryIsExtra && !countrySelected)
return false;
const hasSelectedSkin = c.countrySprites.filter(s => s.mapName === mapSkin()).length > 0;
if (!hasSelectedSkin)
return false;
return true;
})}>
{(country, ix) => {
return <MapCountry countrySprite={country.countrySprites.filter(s => s.mapName === mapSkin())[0]} />
}}
</For>
In short you can toggle between different mapSkin() and different characters(), both of which currently have two settings.
It works OK when you go from no characters selected to a few selected, or when you seemingly replace all the sprites, but as soon as the resulting list expands or contracts I get the omnious error:
Error: Failed to execute 'replaceChild' on 'Node': The node to be replaced is not a child of this node.
I have had this error for a few weeks now. Am I using stores incorrectly?