diff --git a/src/core.js b/src/core.js index d5b8cddc3..5da0f82ca 100644 --- a/src/core.js +++ b/src/core.js @@ -1,5 +1,5 @@ /* eslint-disable no-bitwise */ -import {checkCallback, hasOwn, invokeRedrawable} from "./util.js" +import {checkCallback, hasOwn, invokeRedrawable, noop} from "./util.js" export {m as default} @@ -773,7 +773,7 @@ var removeNodeDispatch = [ removeNode, removeElement, removeInstance, - () => {}, + noop, (old) => currentHooks.push(old), removeFragment, removeFragment, diff --git a/src/std/lazy.js b/src/std/lazy.js index 20aac285a..d1e93e552 100644 --- a/src/std/lazy.js +++ b/src/std/lazy.js @@ -1,6 +1,6 @@ import m from "../core.js" -import {checkCallback} from "../util.js" +import {checkCallback, noop} from "../util.js" var lazy = (opts) => { checkCallback(opts.fetch, false, "opts.fetch") @@ -15,6 +15,7 @@ var lazy = (opts) => { return opts.pending && opts.pending() } var init = async () => { + init = noop try { Comp = await opts.fetch() if (typeof Comp !== "function") { @@ -31,9 +32,7 @@ var lazy = (opts) => { } return (attrs) => { - var f = init - init = null - if (typeof f === "function") f() + init() return m(Comp, attrs) } } diff --git a/src/std/rate-limit.js b/src/std/rate-limit.js index 272ae1ab9..89bf832bf 100644 --- a/src/std/rate-limit.js +++ b/src/std/rate-limit.js @@ -1,5 +1,7 @@ /* global performance, setTimeout, clearTimeout */ +import {noop} from "../util.js" + var validateDelay = (delay) => { if (!Number.isFinite(delay) || delay <= 0) { throw new RangeError("Timer delay must be finite and positive") @@ -12,14 +14,12 @@ var rateLimiterImpl = (delay = 500, isThrottler) => { var closed = false var start = 0 var timer = 0 - var resolveNext + var resolveNext = noop var callback = () => { timer = undefined - if (typeof resolveNext === "function") { - resolveNext(false) - resolveNext = undefined - } + resolveNext(false) + resolveNext = noop } var rateLimiter = async (ignoreLeading) => { @@ -27,10 +27,8 @@ var rateLimiterImpl = (delay = 500, isThrottler) => { return true } - if (typeof resolveNext === "function") { - resolveNext(true) - resolveNext = null - } + resolveNext(true) + resolveNext = noop if (timer) { if (isThrottler) { @@ -66,10 +64,8 @@ var rateLimiterImpl = (delay = 500, isThrottler) => { if (closed) return closed = true clearTimeout(timer) - if (typeof resolveNext === "function") { - resolveNext(true) - resolveNext = null - } + resolveNext(true) + resolveNext = noop } return rateLimiter diff --git a/src/std/tracked.js b/src/std/tracked.js index a4d0a6bb1..bb2553481 100644 --- a/src/std/tracked.js +++ b/src/std/tracked.js @@ -65,7 +65,7 @@ import {checkCallback} from "../util.js" * @property {() => Array<[K, V]>} list * @property {(key: K) => boolean} has * @property {(key: K) => undefined | V} get - * @property {(key: K, value: V) => void} track + * @property {(key: K, value: V) => void} set * @property {(key: K, value: V) => void} replace * @property {(key: K) => boolean} delete */ diff --git a/src/util.js b/src/util.js index c8bb2f257..53dea3e9f 100644 --- a/src/util.js +++ b/src/util.js @@ -16,3 +16,5 @@ export var checkCallback = (callback, allowNull, label = "callback") => { throw new TypeError(`\`${label}\` must be a function${allowNull ? " if provided." : "."}`) } + +export var noop = () => {}