nyaf
nyaf copied to clipboard
n-else always showing up even n-if true
Hi everyone,
n-else was not working for me, so I decided to dive into the code to see if I could fixe it. I have a fix I don't know if it's the best one but it worked for me.
//add globaly a record to be able to track the n-elses value :
const elses: Record<string, boolean> = {};
// add locally a variable to know if the n-if is on or off or not present at all
let nIf: boolean | undefined = undefined;
case 'n-if':
ifStore = !!value;
nIf = ifStore // set the nIf variable with the value of the prop n-if
break;
case 'n-else':
// if nif is undefined meaning there i a n-else without n-if throw an error
if (nIf === undefined)
throw new Error("cannot use n-else without n-if")
// record the state of n-if ( if true don't show n-else if false show n-else)
elses[props['n-else']] = !nIf
break;
// check if the current element is a slot and it has the same name
// as the one provided in the n-else attribute and if we can show it
if (newElement.tagName.toLowerCase() === "slot") {
const name = newElement.attributes['name']?.value
if (name && elses[name] === false) {
return []
}
}
Voila,