Skip to content

Commit

Permalink
feat(polyfill): add polyfill for composite key and composite symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Jun 14, 2023
1 parent ee3dcf7 commit e1525cd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
27 changes: 27 additions & 0 deletions polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2023-latest Tomoki Miyauchi. All rights reserved. MIT license.
// This module is browser compatible.

/**
* @example
* ```ts
* import "https://deno.land/x/composition_key@$VERSION/polyfill.ts";
* import { assert } from "https://deno.land/std/testing/asserts.ts";
*
* assert(compositeKey);
* assert(compositeSymbol);
* ```
*/

// deno-lint-ignore-file no-var ban-types

import { compositeKey, compositeSymbol, type Ref } from "./composite.ts";

declare global {
var compositeKey: (
...parts: [object, ...unknown[]] | [...unknown[], object]
) => Ref;
var compositeSymbol: (...parts: readonly unknown[]) => symbol;
}

globalThis.compositeKey = compositeKey;
globalThis.compositeSymbol = compositeSymbol;
20 changes: 20 additions & 0 deletions polyfill_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023-latest Tomoki Miyauchi. All rights reserved. MIT license.

import "./polyfill.ts";
import { assert, describe, it } from "./_dev_deps.ts";
import {
compositeKey as _compositeKey,
compositeSymbol as _compositeSymbol,
} from "./composite.ts";

describe("compositeKey", () => {
it("should define global", () => {
assert(compositeKey === _compositeKey);
});
});

describe("compositeSymbol", () => {
it("should define global", () => {
assert(compositeSymbol === _compositeSymbol);
});
});

0 comments on commit e1525cd

Please sign in to comment.