avoid Object.fromEntries() and some instances of globalThis
Not supported on early iOS 12. This can be reverted after iOS 12 support is dropped, which should be soon.
This commit is contained in:
parent
0cd4c9431a
commit
52ea7c2a05
@ -23,12 +23,17 @@ function toFluentNumber(num: number): FluentNumber {
|
|||||||
function formatArgs(
|
function formatArgs(
|
||||||
args: Record<string, FluentVariable>,
|
args: Record<string, FluentVariable>,
|
||||||
): Record<string, FluentVariable> {
|
): Record<string, FluentVariable> {
|
||||||
return Object.fromEntries(
|
const entries: [string, FluentVariable][] = Object.entries(args).map(
|
||||||
Object.entries(args).map(([key, value]) => [
|
([key, value]) => [
|
||||||
key,
|
key,
|
||||||
typeof value === "number" ? toFluentNumber(value) : value,
|
typeof value === "number" ? toFluentNumber(value) : value,
|
||||||
]),
|
],
|
||||||
);
|
);
|
||||||
|
const out: Record<string, FluentVariable> = {};
|
||||||
|
for (const [key, value] of entries) {
|
||||||
|
out[key] = value;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMessage(
|
export function getMessage(
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
export const runtimeLibraries = {};
|
export const runtimeLibraries = {};
|
||||||
|
|
||||||
// Export require() as a global.
|
// Export require() as a global.
|
||||||
(globalThis as any).require = function (name: string): unknown {
|
(window as any).require = function (name: string): unknown {
|
||||||
const lib = runtimeLibraries[name];
|
const lib = runtimeLibraries[name];
|
||||||
if (lib === undefined) {
|
if (lib === undefined) {
|
||||||
throw new Error(`Cannot require(${name}) at runtime.`);
|
throw new Error(`Cannot require(${name}) at runtime.`);
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
/* eslint
|
||||||
|
@typescript-eslint/no-explicit-any: "off",
|
||||||
|
*/
|
||||||
|
|
||||||
// A standalone bundle that adds mutateNextCardStates to the anki namespace.
|
// A standalone bundle that adds mutateNextCardStates to the anki namespace.
|
||||||
// When all clients are using reviewer.js directly, we can get rid of this.
|
// When all clients are using reviewer.js directly, we can get rid of this.
|
||||||
|
|
||||||
import { mutateNextCardStates } from "./answering";
|
import { mutateNextCardStates } from "./answering";
|
||||||
|
|
||||||
globalThis.anki.mutateNextCardStates = mutateNextCardStates;
|
(window as any).anki.mutateNextCardStates = mutateNextCardStates;
|
||||||
|
Loading…
Reference in New Issue
Block a user