milomg / reactively

MIT License
415 stars 23 forks source link

Fixed effects adding #2

Closed nin-jin closed 1 year ago

nin-jin commented 1 year ago

Check for effect scheduling before state update

milomg commented 1 year ago

Nice find, thank you!

nin-jin commented 1 year ago

But why this don't work?

let res = []

const { Reactive, stabilize } = $mol_import.module(
    'https://esm.sh/@reactively/core'
)
const A = new Reactive(0)
const H = new Reactive( () => res.push( A.get() ), true )
H.get()

A.set(1)
stabilize()

$mol_assert_like( res, [ 0, 1 ] )

Sandbox

nowylie commented 1 year ago

That's likely because the @reactively/core npm package hasn't been updated/published in a while, so the version distributed via npm doesn't have this fix. I noticed the bad effect behaviour while experimenting with this lib. Using the latest version from main (with this fix) works well though.