Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 738 Bytes

microtask.md

File metadata and controls

32 lines (21 loc) · 738 Bytes

Microtask Controller

Add functions to the microtask queue.

How to use

Add a Microtask controller to a web component. Provide a callback.

Call Microtask.queue() to push the callback to the microtask queue.

In the example below, a Microtask controller queues a render when the width attribute changes.

import { Microtask } from "wctk";

class MyElement extends HTMLElement {
	static observedAttributes = ["width"];

	#rc = new Microtask(this, [this.#render]);

	#render() {
		// update DOM here!
	}

	// lifecycle method
	attributeChangedCallback() {
		this.#rc.queue();
	}
}

The Microtask.queue() method can be called multiple times but the provided callback will only be called once per microtask queue.