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

Shorthand syntax for "Auto" reactions #11

Open
aleclarson opened this issue Oct 25, 2019 · 4 comments
Open

Shorthand syntax for "Auto" reactions #11

aleclarson opened this issue Oct 25, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@aleclarson
Copy link
Collaborator

aleclarson commented Oct 25, 2019

"Reactions" are unobserved side effects in response to an observed computation.

The current way to do this:

auto(() => {
  // Observed computation here
  noto(() => {
    // Unobserved side effects here
  })
})

The proposed way to do this:

auto(
  () => {
    // Observed computation here
  },
  result => {
    // Unobserved side effects here
  }
)

The bonus (of course) being that you don't need to import noto.

@aleclarson aleclarson added the enhancement New feature or request label Oct 25, 2019
@aleclarson
Copy link
Collaborator Author

aleclarson commented Oct 25, 2019

Another option is to add a then method to the Auto class:

auto(() => {
  // Observed computation here
}).then(result => {
  // Unobserved side effects here
})

The bonus being that then callbacks could potentially be chained together.

Naming it then is both good and (mostly) bad. Familiar but probably confusing.

And it's similar to when(() => { ... }).then(() => { ... }) which already exists. 😮

@ryanking1809
Copy link
Contributor

What would be you thoughts on just passing an optional desired observables array? And eliminating no() and noto() - a bit like in React's useEffect. That way you can mix observed and nonObserved in the one function instead of splitting it into to two.

auto(
  () => {
    // Observed computation here
  },
  [
    // desired observables here
  ]
)

@aleclarson
Copy link
Collaborator Author

aleclarson commented Nov 16, 2019

@ryanking1809 I think that introduces unnecessary maintenance burden, and avoiding an extra function isn't worth that cost. For example, if you start using another observable value, you need to also add it to the array argument. If you forget, you'll get potentially confusing bugs.

Also, you'd have to repeat yourself quite a bit if you're reaching into a deeply nested structure.

Lastly, how would you specify observed properties in the array argument? I think it's all a bit too much trickery. :)

@ryanking1809
Copy link
Contributor

@aleclarson Yeah that's fair, you've won me over ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants