Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy state: Maybe remove $ #780

Open
josephjclark opened this issue Sep 25, 2024 · 1 comment
Open

Lazy state: Maybe remove $ #780

josephjclark opened this issue Sep 25, 2024 · 1 comment

Comments

@josephjclark
Copy link
Collaborator

josephjclark commented Sep 25, 2024

Lazy state is proving a bit hard for people (even people on the team) to understand

The story for new users is:

Use $ to access state

Cool, but then they open up a callback and it breaks. So now the rule is:

Use $ to access state, unless in a callback

Which I suppose isn't too bad, but does require a certain mindfulness.

Why don't we drop $ entirely and just treat state as a special entity in the compiler? All the rules we apply to $ now just apply to the special variable state. Which means: if we see state passed into an operation at the top level, we wrap it up in a lazy function.

Reasons for:

  • This is so much easier for users. State Just Works all the time now
  • We barely even need to document this stuff

Reasons against:

  • I have a natural, philosophic aversion to special variables
  • Inside a callback you still need to remember to declare the state parameter (I suppose we could automate this in the compiler?)
  • We are hiding magic away but magic is still happening. Isn't that bad? One thing I've tried to do in v2 is remove magic, to make things more transparent (which doesn't necessarily mean simpler). Maybe users really do need to understand how lazy state works?
  • Declaring state at the top of your code will cause problems, ie, const state = {}. But that's true anyway, and why would you do that? We could even compiler warn against this

I'm warming to the idea that we go ahead and do this. I think we do still need to document something about what's happening, especially if users look at their compiled code. But it would be heavy advanced stuff.

@github-project-automation github-project-automation bot moved this to New Issues in v2 Sep 25, 2024
@josephjclark josephjclark changed the title Lazy state: consolidate $ and state Lazy state: Maybe remove $ Sep 25, 2024
@josephjclark
Copy link
Collaborator Author

We can remove a lot of docs by doing this you know. We just need an expandable box saying something like "when you reference state at the top level, it will always be lazily evaluated. Here's what the compiler does to your code".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New Issues
Development

No branches or pull requests

1 participant