-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contexts): adds support for passing a context of either 'window'…
…, 'worker', or 'node' as a query parameter Some polyfills only work in specific environments such as where the 'window' object is available. Other polyfills work in several environments, but ship different versions for different environments. This commit adds a new (optional) query parameter, 'context', which can be either 'window', 'worker', or 'node'. If it isn't given, it defaults to 'window'. When a set of polyfills is requested, those that doesn't support the given context won't be returned. For example, if you request 'request-animation-frame', and pass in 'worker' as the context, the polyfill won't be added, even if you also pass in the 'force' option. Fixes #2
- Loading branch information
Showing
10 changed files
with
693 additions
and
316 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,16 @@ | ||
import {stringTuple} from "../util/type/string-tuple"; | ||
import {ElementOf} from "../util/type/element-of"; | ||
|
||
export const POLYFILL_CONTEXTS = stringTuple("node", "window", "worker"); | ||
|
||
export type PolyfillContext = ElementOf<typeof POLYFILL_CONTEXTS>; | ||
|
||
export const NODE_CONTEXT: Set<PolyfillContext> = new Set(stringTuple("node")); | ||
export const WINDOW_CONTEXT: Set<PolyfillContext> = new Set(stringTuple("window")); | ||
export const WORKER_CONTEXT: Set<PolyfillContext> = new Set(stringTuple("worker")); | ||
|
||
export const WINDOW_NODE_CONTEXT: Set<PolyfillContext> = new Set([...WINDOW_CONTEXT, ...NODE_CONTEXT]); | ||
|
||
export const WINDOW_WORKER_CONTEXT: Set<PolyfillContext> = new Set([...WINDOW_CONTEXT, ...WORKER_CONTEXT]); | ||
|
||
export const ALL_CONTEXTS: Set<PolyfillContext> = new Set([...NODE_CONTEXT, ...WINDOW_WORKER_CONTEXT]); |
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,4 @@ | ||
/** | ||
* Make all properties in T deep-optional | ||
*/ | ||
export type DeepPartial<T> = {[P in keyof T]?: DeepPartial<T[P]>}; |
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 @@ | ||
export type ElementOf<ArrayType> = ArrayType extends (infer ElementType)[] ? ElementType : never; |
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 @@ | ||
export const stringTuple = <T extends string[]>(...args: T) => args; |