Ahab
Ahab

Reputation: 61

Why does the vue effect not run through the scheduler when the effect is initialized?

Why does the vue effect not run through the scheduler when the effect is initialized?

effect(
  () => {
    console.log('effect');
  },
  {
    scheduler: (job) => {
      console.log('run by scheduler');
      job();
    },
  },
);

Why was it designed this way?

Upvotes: 0

Views: 99

Answers (1)

Ahab
Ahab

Reputation: 61

I found a way to make the effect run through the scheduler when it inits.

const scheduler = (job) => {
  console.log('run by scheduler');
  job();
}

const e = effect(
  () => {
    console.log('effect');
  },
  {
    scheduler,
    lazy: true,
  },
);
scheduler(e) // init run

Upvotes: 1

Related Questions