2 ms·
I've seen so many javascript libraries go down this path. The one I always go back to as the #1 example of this is RiotJS. The very first release of that was l
by bob1029 3y ago
I've seen so many javascript libraries go down this path.
The one I always go back to as the #1 example of this is RiotJS. The very first release of that was like a breath of fresh air - it was the new, simple, no-nonsense way to build SPAs, etc. You can see it plain as day in their migration guide.
Old:
<my-component>
<p class={ active: isActive, disabled: isDisabled }>hello</p>
</my-component>
New:
function classNames(classes) {
return Object.entries(classes).reduce((acc, item) => {
const [key, value] = item
if (value) return [...acc, key]
return acc
}, []).join(' ')
}
// install the classNames plugin
riot.install(function(component) {
// add the classNames helper to all the riot components
component.classNames = classNames
return component
})
<my-component>
<p class={
classNames({
active: isActive,
disabled: isDisabled
})
}>hello</p>
</my-component>
https://riot.js.org/migration-guide/ https://riot.js.org/migration-guide/
This stuff is absolutely insane to me.