Skip to content

Make preloadFont callback optional #346

@crystalfp

Description

@crystalfp

First, thanks for the library, it is really useful!
My application is ElectronJS + Vue + vite + Typescript.
I preload font glyphs but don't need to do anything at the end of the preload. So currently I do:

	preloadFont({
			font: localRoboto,
			characters: "ABC"
		},
		() => {}
	);

This works, but if I don't put the no-op callback, vite complains at runtime, even if I clean its cache:

Unhandled rejection TypeError: callback is not a function
    at http://localhost:5173/node_modules/.vite/deps/troika-three-text.js?v=30d82b0d:4648:7

Note that omitting the callback seems valid because preloadFont() calls getTextRenderInfo() that explicitly checks for callback defined and doesn't call it if not defined.
BTW, I typed the function in troika-three-text.d.ts as: declare function preloadFont(options: {font: string, characters: string}, callback?: () => void): void;

I don't understand if I'm doing something wrong or it is a feature to be added to Troika text.
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions