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

Reactivity pattern not allowed #32

Closed
philippe-wm opened this issue Oct 2, 2022 · 3 comments
Closed

Reactivity pattern not allowed #32

philippe-wm opened this issue Oct 2, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@philippe-wm
Copy link

Your Question
How can we make the 2nd pattern valid wrt reactivity rule?

// OK
function createBar(v: Accessor<unknown>): void {...}
createBar(() => bar());

// KO
function createFoo(v: { onBar: Accessor<unknown> }): void {...}
createFoo({ onBar: () => bar() });
@philippe-wm philippe-wm added the question Further information is requested label Oct 2, 2022
@joshwilsonvu
Copy link
Collaborator

Thanks for the question. Since the reactivity rule can't know the implementation of your custom hooks, it should be permissive about calling it with signals. Currently it looks for arguments that are inline functions and allows reactivity there, but it misses anything else like in your case.

I think I'll call this a bug, because your code looks perfectly valid--the rule needs to be more flexible around custom hooks. Look for a fix in the next release!

@joshwilsonvu joshwilsonvu added bug Something isn't working and removed question Further information is requested labels Oct 2, 2022
@philippe-wm
Copy link
Author

philippe-wm commented Oct 10, 2022

Maybe related @joshwilsonvu :

  const [baz, setBaz] = createSignal(0);

  function getBar(): unknown {
    return props.params.bar;
  }

  // with or without this `createState` function we get the reactivity warning
  const state = createState({
    get foo() { // ok
      return props.params.foo;
    },
    get bar() { // ok
      return getBar();
    },
    get baz() { // reactity warning
      return baz();
    }
  });

  const state = {
    get foo() { // ok
      return props.params.foo;
    },
    get bar() { // ok
      return getBar();
    },
    get baz() { // reactity warning
      return baz();
    }
  };

@joshwilsonvu
Copy link
Collaborator

The warnings you're seeing should be taken care of in v0.7.4. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants