Skip to content

Commit

Permalink
Fix a type comment, make things use a shared noop where helpful
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-claudia committed Oct 30, 2024
1 parent cd26097 commit 8cafcfe
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -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}

Expand Down Expand Up @@ -773,7 +773,7 @@ var removeNodeDispatch = [
removeNode,
removeElement,
removeInstance,
() => {},
noop,
(old) => currentHooks.push(old),
removeFragment,
removeFragment,
Expand Down
7 changes: 3 additions & 4 deletions src/std/lazy.js
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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") {
Expand All @@ -31,9 +32,7 @@ var lazy = (opts) => {
}

return (attrs) => {
var f = init
init = null
if (typeof f === "function") f()
init()
return m(Comp, attrs)
}
}
Expand Down
22 changes: 9 additions & 13 deletions src/std/rate-limit.js
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -12,25 +14,21 @@ 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) => {
if (closed) {
return true
}

if (typeof resolveNext === "function") {
resolveNext(true)
resolveNext = null
}
resolveNext(true)
resolveNext = noop

if (timer) {
if (isThrottler) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/std/tracked.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {}

0 comments on commit 8cafcfe

Please sign in to comment.