import type { Task , IScheduler } from "./api.js" ; /**
 *  IScheduler implementation which queues component updates (or other
 * tasks) and then only processes them during next RAF cycle. Supports task
 * cancellation.
 *
 *  remarks See  setScheduler and  NullScheduler .
  export class RAFScheduler implements IScheduler { tasks : Map < any , Task [ ] > ; raf : number ; constructor ( ) { this . tasks = new Map ( ) ; this . raf = - 1 ; } add ( scope , fn ) { const tasks = this . tasks . get ( scope ) ; tasks ? tasks . push ( fn ) : this . tasks . set ( scope , [ fn ] ) ; this . raf < 0 && ( this . raf = requestAnimationFrame ( this . update . bind ( this ) ) ) ; } cancel ( scope ) { this . tasks . delete ( scope ) ; } update ( ) { for ( let tasks of this . tasks . values ( ) ) { for ( let i = tasks . length ; i -- > 0 ; tasks [ i ] ( ) ) ; } this . tasks . clear ( ) ; this . raf = - 1 ; } } /**
 * Dummy (and default)  IScheduler implementation which immediately
 * processes component updates.
 *
 *  remarks See  setScheduler and  RAFScheduler .
  export class NullScheduler implements IScheduler { add ( _ , fn ) { fn ( ) ; } cancel ( ) { } } export let SCHEDULER = new NullScheduler ( ) ; param s returns export const setScheduler = ( s ) => ( SCHEDULER = s ) ;