-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more type checks, unify auto-redraw logic, optimize element creat…
…ion better
- Loading branch information
1 parent
0c99734
commit 814261f
Showing
12 changed files
with
105 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import m from "../core.js" | ||
|
||
import {checkCallback, invokeRedrawable} from "../util.js" | ||
|
||
function Init({f}, old) { | ||
if (old) return m.retain() | ||
var ctrl = new AbortController() | ||
queueMicrotask(async () => { | ||
if ((await f(ctrl.signal)) !== false) this.redraw() | ||
}) | ||
queueMicrotask(() => invokeRedrawable(this.redraw, f, undefined, ctrl.signal)) | ||
return m.remove(() => ctrl.abort()) | ||
} | ||
|
||
var init = (f) => m(Init, {f}) | ||
var init = (f) => m(Init, {f: checkCallback(f)}) | ||
|
||
export {init as default} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
export var hasOwn = {}.hasOwnProperty | ||
|
||
export var invokeRedrawable = async (redraw, fn, thisValue, ...args) => { | ||
if (typeof fn === "function") { | ||
thisValue = Reflect.apply(fn, thisValue, args) | ||
if (thisValue === "skip-redraw") return | ||
if (thisValue && typeof thisValue.then === "function" && (await thisValue) === "skip-redraw") return | ||
redraw() | ||
} | ||
} | ||
|
||
export var checkCallback = (callback, allowNull, label = "callback") => { | ||
if (allowNull && callback == null || typeof callback === "function") { | ||
return callback | ||
} | ||
|
||
throw new TypeError(`\`${label}\` must be a function${allowNull ? " if provided." : "."}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.