I am trying to build a text editor, where _cursor
is position of the cursor. setInterval 4000 seconds
is like user moving the cursor. In which case I want to run an effect.
But often I set the cursor as a side effect internally, for example when some text is deleted or added or an undo. In that case I don't want to run the createEffect
in the example.
So how do I make the createEffect
only run for second setInterval 4000
and not for the first setInterval
.
import { render } from "solid-js/web";
import { For, createSignal, createEffect, on } from "solid-js";
function Counter() {
const [_cursor, _setCursor] = createSignal(100)
createEffect(on(_cursor, (v, p) => {
if (p && v < p) {
console.log('reset')
}
}))
setInterval(() => {
_setCursor(_cursor() - 1)
}, 500)
setInterval(() => {
_setCursor(_cursor() - 1)
}, 4000)
return (<>
<span>{_cursor()}</span>
</>)
}
render(() => <Counter />, document.getElementById("app"));