From 2e590072148c85bbc479ab49aa9556b0a2cfaff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 5 Mar 2020 13:05:41 +0100 Subject: move Web APIs to cli/js/web/ --- cli/js/mixins/dom_iterable.ts | 85 ------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 cli/js/mixins/dom_iterable.ts (limited to 'cli/js/mixins') diff --git a/cli/js/mixins/dom_iterable.ts b/cli/js/mixins/dom_iterable.ts deleted file mode 100644 index 976d81be7..000000000 --- a/cli/js/mixins/dom_iterable.ts +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { DomIterable } from "../dom_types.ts"; -import { requiredArguments } from "../util.ts"; -import { exposeForTest } from "../internals.ts"; - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -type Constructor = new (...args: any[]) => T; - -/** Mixes in a DOM iterable methods into a base class, assumes that there is - * a private data iterable that is part of the base class, located at - * `[dataSymbol]`. - */ -export function DomIterableMixin( - Base: TBase, - dataSymbol: symbol -): TBase & Constructor> { - // we have to cast `this` as `any` because there is no way to describe the - // Base class in a way where the Symbol `dataSymbol` is defined. So the - // runtime code works, but we do lose a little bit of type safety. - - // Additionally, we have to not use .keys() nor .values() since the internal - // slot differs in type - some have a Map, which yields [K, V] in - // Symbol.iterator, and some have an Array, which yields V, in this case - // [K, V] too as they are arrays of tuples. - - const DomIterable = class extends Base { - *entries(): IterableIterator<[K, V]> { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - for (const entry of (this as any)[dataSymbol]) { - yield entry; - } - } - - *keys(): IterableIterator { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - for (const [key] of (this as any)[dataSymbol]) { - yield key; - } - } - - *values(): IterableIterator { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - for (const [, value] of (this as any)[dataSymbol]) { - yield value; - } - } - - forEach( - callbackfn: (value: V, key: K, parent: this) => void, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - thisArg?: any - ): void { - requiredArguments( - `${this.constructor.name}.forEach`, - arguments.length, - 1 - ); - callbackfn = callbackfn.bind( - thisArg == null ? globalThis : Object(thisArg) - ); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - for (const [key, value] of (this as any)[dataSymbol]) { - callbackfn(value, key, this); - } - } - - *[Symbol.iterator](): IterableIterator<[K, V]> { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - for (const entry of (this as any)[dataSymbol]) { - yield entry; - } - } - }; - - // we want the Base class name to be the name of the class. - Object.defineProperty(DomIterable, "name", { - value: Base.name, - configurable: true - }); - - return DomIterable; -} - -exposeForTest("DomIterableMixin", DomIterableMixin); -- cgit v1.2.3