@gluonjs/reactivity


@gluonjs/reactivity / packages/reactivity/src / queuePostFlushCallback

Function: queuePostFlushCallback()

queuePostFlushCallback(callback, options?): void

Parameters

callback

SchedulerJob

options?

Omit<SchedulerJobOptions, "phase"> = {}

Returns

void

Example

Schedule work after reactive updates, which is useful for reading DOM or state that must already be settled:

ts
import {
  invalidateJob,
  nextTick,
  queueJob,
  queuePostFlushCallback,
  queuePreFlushCallback,
  type EffectFlush,
  type FlushPhase,
  type SchedulerJob,
  type SchedulerJobOptions,
} from '@gluonjs/reactivity';

const order: string[] = [];
const cancelled: SchedulerJob = () => order.push('cancelled');
const update: SchedulerJob = () => order.push('update');
const phase: FlushPhase = 'update';
const flush: EffectFlush = 'post';
const options: SchedulerJobOptions = { phase, id: 10 };
queuePreFlushCallback(() => order.push('pre'));
queueJob(update, options);
queueJob(cancelled);
invalidateJob(cancelled);
queuePostFlushCallback(() => order.push(flush));
await nextTick();
console.log(order); // ['pre', 'update', 'post']