Skip to content

Commit

Permalink
Switch back to microticks for scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Feb 24, 2023
1 parent 833d7de commit 54ecaa1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
12 changes: 2 additions & 10 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { assign } from './util';
import { diff, commitRoot } from './diff/index';
import options from './options';
import { Fragment } from './create-element';
import { inEvent } from './diff/props';

/**
* Base Component class. Provides `setState()` and `forceUpdate()`, which
Expand Down Expand Up @@ -184,17 +183,10 @@ let rerenderQueue = [];

let prevDebounce;

const microTick =
const defer =
typeof Promise == 'function'
? Promise.prototype.then.bind(Promise.resolve())
: setTimeout;
function defer(cb) {
if (inEvent) {
setTimeout(cb);
} else {
microTick(cb);
}
}

/**
* Enqueue a rerender of a component
Expand All @@ -209,7 +201,7 @@ export function enqueueRender(c) {
prevDebounce !== options.debounceRendering
) {
prevDebounce = options.debounceRendering;
(prevDebounce || defer)(process, inEvent);
(prevDebounce || defer)(process);
}
}

Expand Down
18 changes: 2 additions & 16 deletions src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,15 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
}
}

export let inEvent = false;

/**
* Proxy an event to hooked event handlers
* @param {Event} e The event object from the browser
* @private
*/
function eventProxy(e) {
inEvent = true;
try {
return this._listeners[e.type + false](
options.event ? options.event(e) : e
);
} finally {
inEvent = false;
}
return this._listeners[e.type + false](options.event ? options.event(e) : e);
}

function eventProxyCapture(e) {
inEvent = true;
try {
return this._listeners[e.type + true](options.event ? options.event(e) : e);
} finally {
inEvent = false;
}
return this._listeners[e.type + true](options.event ? options.event(e) : e);
}
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export interface Options {
diffed?(vnode: VNode): void;
event?(e: Event): any;
requestAnimationFrame?(callback: () => void): void;
debounceRendering?(cb: () => void, inEvent: boolean): void;
debounceRendering?(cb: () => void): void;
useDebugValue?(value: string | number): void;
_addHookName?(name: string | number): void;
__suspenseDidResolve?(vnode: VNode, cb: () => void): void;
Expand Down

0 comments on commit 54ecaa1

Please sign in to comment.