Same public API as choo 7.1.0 (use/route/start/mount/toString/emit; choo() callable with or without new, Choo exported). nanobus, nanorouter+wayfarer, nanolru+component cache, nanoraf, nanohref, nanotiming, document-ready and scroll-to-anchor are ported into lib/ with per-file attribution; nanoquery is replaced by URLSearchParams. The v7 node test suite is ported from tape to node:test and passes unchanged in behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014NgfSjHE11oFpoSnLVKLXd
29 lines
793 B
JavaScript
29 lines
793 B
JavaScript
// Ported from nanoraf 3.1.0 (MIT) — https://github.com/choojs/nanoraf
|
|
// Only call requestAnimationFrame when needed.
|
|
|
|
import { ok, equal } from './assert.js'
|
|
|
|
export default function nanoraf (render, raf) {
|
|
equal(typeof render, 'function', 'nanoraf: render should be a function')
|
|
ok(typeof raf === 'function' || typeof raf === 'undefined', 'nanoraf: raf should be a function or undefined')
|
|
|
|
if (!raf) raf = globalThis.requestAnimationFrame
|
|
let redrawScheduled = false
|
|
let args = null
|
|
|
|
return function frame (...frameArgs) {
|
|
if (args === null && !redrawScheduled) {
|
|
redrawScheduled = true
|
|
|
|
raf(function redraw () {
|
|
redrawScheduled = false
|
|
const _args = args
|
|
args = null
|
|
render(..._args)
|
|
})
|
|
}
|
|
|
|
args = frameArgs
|
|
}
|
|
}
|