Day 10 State in Class
From baroque aristocracies of abstract factory providers to the reactive revolution — JavaScript's relationship with classes has been, shall we say, complicated. But Svelte finds the pragmatic middle ground!
Use the $state rune directly in class fields to create reactive properties. When you need more control — like clamping a belief meter between 0 and 100 — make the field private and wrap it in a getter and setter. The compiler transforms these into efficient get/set methods on the class prototype.
Add custom methods like believe() and doubt() to encapsulate your logic. Just remember: when passing methods as event handlers, this binding matters! Either use arrow functions in your class definition or wrap the call in an inline function.
For computed values, $derived works beautifully in classes too — perfect for determining if Santa's belief level has reached critical status. You can even use $state inside the constructor when assigning to properties for the first time.
Like Santa traversing the globe, bolstered by belief and hindered by doubt, your classes can now be both elegant and reactive!