Code example:
import { createCtx, atom } from '@reatom/core'
import { connectLogger } from '@reatom/logger'
const ctx = createCtx()
connectLogger(ctx)
const counterAtom = atom(0, 'counterAtom')
const doubledAtom = atom((ctx) => ctx.spy(counterAtom) * 2, 'doubledAtom')
counterAtom(ctx, 24)
console.log(ctx.get(doubledAtom)) // Should generate log
This code generate in logs only:
42
But if I add subscription before reading
import { createCtx, atom } from '@reatom/core'
import { connectLogger } from '@reatom/logger'
const ctx = createCtx()
connectLogger(ctx, { skipUnnamed: false })
const counterAtom = atom(0, 'counterAtom')
const doubledAtom = atom((ctx) => ctx.spy(counterAtom) * 2, 'doubledAtom')
ctx.subscribe(doubledAtom, () => null) // Subscription added
counterAtom(ctx, 24)
console.log(ctx.get(doubledAtom))
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too