Replies: 2 comments 6 replies
-
| You are fighting syntax, so I don't think this is particularly productive. If I really care about strict encapsulation somewhere, I just write out the getters, but more realistically I would just wrap the entire thing with  function createStore() {
  const store = $state({
    value: undefined,
    foo() { store.value += 2 },
  });
  return store;
} | 
Beta Was this translation helpful? Give feedback.
                  
                    6 replies
                  
                
            -
| I also noticed that if I add  | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I would love to be able to do:
Compiler generates:
Problem is the compiler wraps
valuein$.getcausing it to immediately evaluate.As a workaround I wrote a helper to create the getters and setters:
This would be the ideal usage:
But it compiles to the following which breaks reactivity.
The only way I can use this functions is if I write:
accessorsfunction work if it didn't compile to $.get()https://svelte.dev/playground/d66731cca4b74a429051118875284c37?version=5.39.2
Beta Was this translation helpful? Give feedback.
All reactions