Skip to content

Commit

Permalink
commit staged work
Browse files Browse the repository at this point in the history
  • Loading branch information
mmocny committed May 6, 2024
1 parent 7d81c83 commit ae2bb94
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 15 deletions.
54 changes: 54 additions & 0 deletions sandbox/all-event-types/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script type="module">
const EVENTS = [
"keydown",
"keyup",
"keypress",
// "pointerdown",
// "pointerup",
"pointercancel",
"touchstart",
"touchend",
"touchcancel",
// "mousedown",
// "mouseup",
"gotpointercapture",
"lostpointercapture",
// "click",
"dblclick",
"auxclick",
"contextmenu",
"pointerleave",
"pointerout",
"pointerover",
"pointerenter",
"mouseout",
"mouseover",
"mouseleave",
"mouseenter",
"lostpointercapture",
"dragstart",
"dragend",
"dragenter",
"dragleave",
"dragover",
"drop",
"beforeinput",
"input",
"compositionstart",
"compositionupdate",
"compositionend",
];

function block(ms) {
const target = performance.now() + ms;
while(performance.now() < target);
}

EVENTS.forEach(type => {
document.addEventListener(type, e => {
console.log(`Event type: ${type}`);
block(20);
});
});

</script>
51 changes: 39 additions & 12 deletions sandbox/force-mutation-observers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ async function prefetch() {
}


function triggerMutationObserver(cb) {
function addMutationObserverAndModifyDOMToTriggerIt(cb) {
const targetNode = document.createElement('div');
const observer = new MutationObserver(cb);
// for (const mutation of mutationList) {
// console.log('Mutation detected:', mutation.type);
// }
observer.observe(targetNode, { childList: true });

const dummyNode = document.createElement('span');
targetNode.appendChild(dummyNode);
// targetNode.removeChild(dummyNode);
}

function a() {
Expand All @@ -42,25 +38,25 @@ function b() {
}
function c() {
block(BLOCK);
triggerMutationObserver(function afterMutation() { block(BLOCK); });
addMutationObserverAndModifyDOMToTriggerIt(function afterMutation() { block(BLOCK); });
}

async function dontAwaitFirstDoAwaitBetween() { a(); await 0; block(BLOCK); a(); }
async function doAwaitFirstDoAwaitBetween() { a(); await 0; block(BLOCK); a(); }
async function dontAwaitFirstDontAwaitBetween() { a(); block(BLOCK); a(); }
async function doAwaitFirstDontAwaitBetween() { await 0; a(); block(BLOCK); a(); }

scheduler.postTask(dontAwaitFirstDoAwaitBetween);
scheduler.postTask(doAwaitFirstDoAwaitBetween);
scheduler.postTask(dontAwaitFirstDontAwaitBetween);
scheduler.postTask(doAwaitFirstDontAwaitBetween);
// scheduler.postTask(dontAwaitFirstDoAwaitBetween);
// scheduler.postTask(doAwaitFirstDoAwaitBetween);
// scheduler.postTask(dontAwaitFirstDontAwaitBetween);
// scheduler.postTask(doAwaitFirstDontAwaitBetween);

async function testFetch() {
block(BLOCK);
triggerSyncFetch(function afterFetch() { block(BLOCK); });
}

scheduler.postTask(testFetch);
// scheduler.postTask(testFetch);


async function testPrefetch() {
Expand All @@ -74,4 +70,35 @@ async function testPrefetch() {
});
}

scheduler.postTask(testPrefetch);
// scheduler.postTask(testPrefetch);




function updateColorTo(color) {
console.log(color);
document.body.style.backgroundColor = color;
block(BLOCK);
}


async function testMutationObserverAndYield() {
updateColorTo('red');

requestAnimationFrame(() => {
updateColorTo('green');
});

addMutationObserverAndModifyDOMToTriggerIt((mutationList) => {
for (const mutation of mutationList) {
// console.log('Mutation detected:', mutation.type);
}
updateColorTo('blue');
});

await scheduler.yield();
}

document.body.addEventListener('click', () => {
testMutationObserverAndYield();
});
32 changes: 30 additions & 2 deletions sandbox/presentation-delay-marks-examples/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style>
button:active {
background-color: red;
}
</style>

<script type="module">
import { onLCP, onINP, onCLS } from 'https://unpkg.com/web-vitals@next/attribution?module';
onINP((metric) => {
console.log('web-vitals.js@next', metric.value, metric.attribution);
}, { reportAllChanges: true });

function block(ms) {
const target = performance.now() + ms;
while(performance.now() < target);
Expand All @@ -15,20 +28,35 @@


function updateUI() {
console.log('Button clicked');
console.log('Update UI');
// Just block enough to trigger Event Timing
block(20);
}

function updateExpensiveAnalytics() {
console.log('Update expensive analytics');
block(1000);
}

document.getElementById('myButton').addEventListener('click', async () => {
function startPrerender() {
console.log('Start prerender');
block(1000);
}

const button = document.getElementById('myButton');

button.addEventListener('click', async () => {
updateUI();
await scheduler.yield();
updateExpensiveAnalytics()
});

// button.addEventListener('pointerenter', async () => {
// updateUI();
// await scheduler.yield();
// startPrerender();
// });

</script>

<button id="myButton">Click me</button>
2 changes: 1 addition & 1 deletion sandbox/web-vitals.js-experiment/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onLCP, onINP, onCLS } from 'https://unpkg.com/web-vitals?module';
import { onLCP, onINP, onCLS } from 'https://unpkg.com/web-vitals@next/attribution?module';

function reportWebVitals(url, result) {
console.log(url, result);
Expand Down

0 comments on commit ae2bb94

Please sign in to comment.