-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
182 additions
and
155 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { DomIterable } from "../dom_types"; | ||
|
||
// tslint:disable:no-any | ||
type Constructor<T = {}> = 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<K, V, TBase extends Constructor>( | ||
// tslint:disable-next-line:variable-name | ||
Base: TBase, | ||
dataSymbol: symbol | ||
): TBase & Constructor<DomIterable<K, V>> { | ||
return class DomIterable extends Base { | ||
*entries(): IterableIterator<[K, V]> { | ||
for (const entry of (this as any)[dataSymbol].entries()) { | ||
yield entry; | ||
} | ||
} | ||
|
||
*keys(): IterableIterator<K> { | ||
for (const key of (this as any)[dataSymbol].keys()) { | ||
yield key; | ||
} | ||
} | ||
|
||
*values(): IterableIterator<V> { | ||
for (const value of (this as any)[dataSymbol].values()) { | ||
yield value; | ||
} | ||
} | ||
|
||
forEach( | ||
callbackfn: (value: V, key: K, parent: this) => void, | ||
// tslint:disable-next-line:no-any | ||
thisArg?: any | ||
): void { | ||
for (const [key, value] of (this as any)[dataSymbol].entries()) { | ||
callbackfn.call(thisArg || this, value, key, this); | ||
} | ||
} | ||
|
||
*[Symbol.iterator](): IterableIterator<[K, V]> { | ||
for (const entry of (this as any)[dataSymbol]) { | ||
yield entry; | ||
} | ||
} | ||
}; | ||
} | ||
// tslint:enable:no-any |
Oops, something went wrong.