From reading Rob's blog post, it seems like in const counter = new Signal.State(0); that counter is a stateful and mutable instance. This means that if i want to give someone the ability to read the state but not mutate it, i have to do counter.get.bind(counter), or () => counter.get(), both of which are inconvenient and easy to forget.
Why not have const { get, set } = Signal.State(0)? iow, have it not be newable, and just vend an object that has two standalone functions on it. Usage would be the same, but it'd be much harder to misuse and much easier to pass capabilities around. (i believe this concept is called "lenses" but i might be wrong)
It'd also avoid adding new classes (and thus inheritance/species questions), which is a bonus to many cohorts.
From reading Rob's blog post, it seems like in
const counter = new Signal.State(0);thatcounteris a stateful and mutable instance. This means that if i want to give someone the ability to read the state but not mutate it, i have to docounter.get.bind(counter), or() => counter.get(), both of which are inconvenient and easy to forget.Why not have
const { get, set } = Signal.State(0)? iow, have it not be newable, and just vend an object that has two standalone functions on it. Usage would be the same, but it'd be much harder to misuse and much easier to pass capabilities around. (i believe this concept is called "lenses" but i might be wrong)It'd also avoid adding new classes (and thus inheritance/species questions), which is a bonus to many cohorts.