You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is more a dx issue, but I see a pattern frequently where I'd like to be able to bind to a state var, but prevent accidental writes to it because writes should be handled by a helper that adjusts multiple state variables or performs other side effects. It would be nice to have something like State.readonly() that returned a wrapped version where get stateVar.val worked but set stateVar.val threw an exception.
It might look something like this:
"readonly"(){let_this=thisreturn{
..._this,set"val"(v){thrownewError(`State is read-only`)},}}
This is more a dx issue, but I see a pattern frequently where I'd like to be able to
bind
to a state var, but prevent accidental writes to it because writes should be handled by a helper that adjusts multiple state variables or performs other side effects. It would be nice to have something likeState.readonly()
that returned a wrapped version whereget stateVar.val
worked butset stateVar.val
threw an exception.It might look something like this:
Or, if you don't want to actually add that to the code, I can basically get what I need from TS type checking
The text was updated successfully, but these errors were encountered: