Hey there! Hope you’re having an amazing week! đ
If you’re new here, let me introduce you to Cardboard.jsâa lightweight, reactive web framework that lets you build dynamic web apps with just JavaScript or TypeScript. No HTML templates, no unnecessary boilerplateâjust clean, reactive code.
Curious? Check out the repository to dive right in!
This post is a devlog and changelog about the latest updates to Cardboard.js. Itâs all about making the framework more intuitive, developer-friendly, and powerful. Letâs dive into whatâs new and why it matters!
đ The Big Picture: Making Names Make Sense
One of the biggest challenges in any framework is naming things. Names should be intuitive, descriptive, and align with industry standards. In this update, I focused on renaming key concepts in Cardboard.js to make them easier to understand and use.
Hereâs whatâs changed:
đïž Mount Points: A Cleaner Way to Attach Elements
Previously, Cardboard used the term attach
for managing where elements are added in the DOM. While functional, it wasnât very intuitive. So, Iâve renamed it to mount points, a term thatâs more familiar to developers.
Whatâs New:
-
attach
âmountPoint
-
detach
ârestoreMountPoint
-
attached
âgetMountPoint
-
tag.attach
âtag.mount
New Utilities:
-
resetMountPoints()
â Resets to the first mount point. -
clearMountPoints()
â Clears all mount points. -
withMountPoints(tag, cb)
â Temporarily sets a mount point for scoped operations.
Before and After:
Hereâs how the new API makes your code more readable and intuitive:
Before:
attach(div1);
p.attach('Child of div1');
attach(div2);
p.attach('Child of div2');
detach();
p.attach('Child of div1 again');
attached().append(p('child of div1'));
After:
mountPoint(div1);
p.mount('Child of div1');
mountPoint(div2);
p.mount('Child of div2');
restoreMountPoint();
p.mount('Child of div1 again');
getMountPoint().append(p('child of div1'));
đ Observables: A More Familiar Name
Previously called Consumables, these reactive objects hold values and notify listeners when the value changes. While the functionality was great, the name wasnât. So, Iâve renamed them to Observables, a term thatâs widely recognised in the developer community.
Why This Matters:
Using familiar terminology reduces the learning curve and makes the framework more approachable for new users.
đ§ Computed Observables: Smarter State Management
Cardboard now supports computed observables, which let you derive new reactive values from existing ones. For example:
const count = createObservable(10);
const isAbove18 = compute(count, (newVal) => newVal >= 18);
Previously, this was called intersect
, but Iâve renamed it to compute to align with industry standards.
âš Built-in Compute Helpers: Now Even Better
Cardboard offers a set of pre-built compute helpers like greaterThan
and isEmpty
. These were standalone functions, but now theyâre available as methods directly on Observables for cleaner, more readable code.
Before:
const isAbove18 = greaterThan(age, 18);
After:
const isAbove18 = age.greaterThan(18);
đ Lifecycle Events: Standardized Names
Lifecycle events have been renamed to align with common conventions:
-
start
âmounted
-
removed
âunmounted
-
beforeRemove
âbeforeUnmounted
đŻ Why These Changes Matter
At first glance, these changes might seem small. But they make a huge difference in how intuitive and enjoyable Cardboard.js is to use. By adopting familiar terminology and simplifying APIs, Iâm making it easier for developers to pick up the framework and start building amazing things.
đ Whatâs Next?
Iâm aiming to release the first stable version of Cardboard.js before the end of the year! Thereâs still a lot to do, but Iâm excited about the progress so far.
If youâre interested in contributing or just want to follow along, check out the GitHub repository. Every star, issue, or pull request helps!
â€ïž Join the Community
If you find Cardboard.js interesting, Iâd love your feedback! Whether itâs trying out the framework, reporting bugs, or suggesting features, your input is invaluable.
đ Visit the GitHub Repository
Letâs build something amazing together!