Last 12 weeks · 0 commits
1 of 6 standards met
The library did not appear to work as intended. I could only get it to work for a single slot and only if I was rendering 1 child in the slot content. After some debugging I noticed two issues; Slots share the same state, settings state on a second slot override the first slots content It was always choosing children[0] when evaluating children/content Since all slots shared the same state.content I decided to key the content by the slots name. I also noticed the onChange functions were being called even when the slot in question was not changing. This was due to onChange being an array of update functions and each update was executed when a SlotContent changed. So I applied the same idea to onChange, it is now an object, the key is the slots name and the value is the update function. To address the issue of only being able to render a single child within SlotContent, I updated it to send all of it's children to apply. Then when slot renders the content it will determine if it should pass all the children, or just render the zero node (in the case of a string being the content). A working demo with the updates I've made can be found here. Switch the imports for preact-slots to the released version to see the issues.
Repository: developit/preact-slots. Description: 🕳 Render Preact trees into other Preact trees, like portals. Stars: 156, Forks: 3. Primary language: JavaScript. Languages: JavaScript (100%). Homepage: https://npm.im/preact-slots Topics: preact, preact-components. Open PRs: 4, open issues: 3. Last activity: 5y ago. Community health: 28%. Top contributors: developit, greenkeeper[bot].