SolidJSS
SolidJS10mo ago
gsoutz

I need to run an effect when an async signal or a store signal, or another async signal are equal

import { createEffect, createMemo, createSignal } from 'solid-js';
import { render } from 'solid-js/web';
import { createAsync } from '@solidjs/router'

const rnd_int = () => Math.ceil(Math.random() * 10)

function App() {

  let [a, set_a] = createSignal()
  let [b, set_b] = createSignal()

  let d_a = createAsync(async () => a())
  let d_b = createMemo(() => b())

  const is_diff = createMemo(() => d_a() !== d_b())

  createEffect(() => {
    if (is_diff()){ 
      return
    }
    console.log(a(), b(), a() === b())
  })

  setInterval(() => {
    set_a(rnd_int())
  }, 100)
  setInterval(() => {
    set_b(rnd_int())
  }, 250)

  return (<></>)
}

render(() => <App />, document.getElementById('app')!);


This equality test is supposed to make sure not pass forward when the memos are not equal but it does why, and how can I make sure it only passes when they are equal.
https://playground.solidjs.com/anonymous/70c547e4-4c55-407f-a31a-d369aa3028eb
Quickly discover what the solid compiler will generate from your JSX template
Was this page helpful?