Should we support direct acess/assignment? #127
jmeistrich
started this conversation in
General
Replies: 1 comment 3 replies
-
I am not quite familiar with internals of this library but is it possible to add support for using observables in this way? const obs = observable({ fname: 'hi', lname: 'there' });
const fname = obs.fname;
// becomes the same as
const fname = obs.fname.peek();
obs.fname = 'hello';
// becomes the same as
obs.fname.set('hello');
const fname = obs.fname$;
// becomes the same as
const fname = obs.fname.get();
// $ can refer to some magic work :)
// and for accessing the observable itself, we could call another method on it
const actual_obervable = obs.fname.obs() // or anything you would prefer I really like this way of working with observables since I mostly work with values other than observables. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Legend-State 1.3.0-next.0 adds an experimental new feature: using a _ prefix as a shorthand for get/set. This allows direct access and assignment, which is shorter and easier than using get()/set(). What do you think? Is this an improvement that you would use?
We're not planning to remove get/set - this is an alternative which some people said they’d find easier to use. Many teams prefer the safety of calling set() to modify state to prevent accidental changes, so we have a way to disable it entirely.
I think this might make Legend-State more approachable and familiar to use? As I'm experimenting with it, I find I prefer the clarity of
value.get()
within React components, but_value
feels shorter and friendlier within computed/observe. I'm curious what all of you think 🤔Beta Was this translation helpful? Give feedback.
All reactions