Mastodon Feed: Post

Mastodon Feed

slightlyoff@toot.cafe ("Alex Russell") wrote:

In code, that might look like:

```js
// Instead of rAF and double-rAF dances...

let width;
let foo = document.getElementById("foo");
// New read-only phase
window.requestAfterLayout(() => {
// Writing styles throws, but reads are cheap
width = foo.innerWidth; // Never forces layout!
});
window.requestBeforeLayout(() => {
// Like today, but writes don't take effect until later
foo.attributeStylMap.set("width", CSS.px(width * 2));
assert(width == foo.innerWidth); // true!
});
```