project files added

This commit is contained in:
mhalfmann
2021-06-15 16:00:08 +02:00
parent e156e2f053
commit db46afa351
13928 changed files with 1569902 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import { root } from './root';
export class RequestAnimationFrameDefinition {
cancelAnimationFrame: (handle: number) => void;
requestAnimationFrame: (cb: () => void) => number;
constructor(root: any) {
if (root.requestAnimationFrame) {
this.cancelAnimationFrame = root.cancelAnimationFrame.bind(root);
this.requestAnimationFrame = root.requestAnimationFrame.bind(root);
} else if (root.mozRequestAnimationFrame) {
this.cancelAnimationFrame = root.mozCancelAnimationFrame.bind(root);
this.requestAnimationFrame = root.mozRequestAnimationFrame.bind(root);
} else if (root.webkitRequestAnimationFrame) {
this.cancelAnimationFrame = root.webkitCancelAnimationFrame.bind(root);
this.requestAnimationFrame = root.webkitRequestAnimationFrame.bind(root);
} else if (root.msRequestAnimationFrame) {
this.cancelAnimationFrame = root.msCancelAnimationFrame.bind(root);
this.requestAnimationFrame = root.msRequestAnimationFrame.bind(root);
} else if (root.oRequestAnimationFrame) {
this.cancelAnimationFrame = root.oCancelAnimationFrame.bind(root);
this.requestAnimationFrame = root.oRequestAnimationFrame.bind(root);
} else {
this.cancelAnimationFrame = root.clearTimeout.bind(root);
this.requestAnimationFrame = function(cb) { return root.setTimeout(cb, 1000 / 60); };
}
}
}
export const AnimationFrame = new RequestAnimationFrameDefinition(root);
+18
View File
@@ -0,0 +1,18 @@
/**
* An error thrown when an element was queried at a certain index of an
* Observable, but no such index or position exists in that sequence.
*
* @see {@link elementAt}
* @see {@link take}
* @see {@link takeLast}
*
* @class ArgumentOutOfRangeError
*/
export class ArgumentOutOfRangeError extends Error {
constructor() {
const err: any = super('argument out of range');
(<any> this).name = err.name = 'ArgumentOutOfRangeError';
(<any> this).stack = err.stack;
(<any> this).message = err.message;
}
}
+18
View File
@@ -0,0 +1,18 @@
/**
* An error thrown when an Observable or a sequence was queried but has no
* elements.
*
* @see {@link first}
* @see {@link last}
* @see {@link single}
*
* @class EmptyError
*/
export class EmptyError extends Error {
constructor() {
const err: any = super('no elements in sequence');
(<any> this).name = err.name = 'EmptyError';
(<any> this).stack = err.stack;
(<any> this).message = err.message;
}
}
+30
View File
@@ -0,0 +1,30 @@
export class FastMap {
private values: Object = {};
delete(key: string): boolean {
this.values[key] = null;
return true;
}
set(key: string, value: any): FastMap {
this.values[key] = value;
return this;
}
get(key: string): any {
return this.values[key];
}
forEach(cb: (value: any, key: any) => void, thisArg?: any): void {
const values = this.values;
for (let key in values) {
if (values.hasOwnProperty(key) && values[key] !== null) {
cb.call(thisArg, values[key], key);
}
}
}
clear(): void {
this.values = {};
}
}
+238
View File
@@ -0,0 +1,238 @@
/**
Some credit for this helper goes to http://github.com/YuzuJS/setImmediate
*/
import { root } from './root';
export class ImmediateDefinition {
setImmediate: (cb: () => void) => number;
clearImmediate: (handle: number) => void;
private identify(o: any): string {
return this.root.Object.prototype.toString.call(o);
}
tasksByHandle: any;
nextHandle: number;
currentlyRunningATask: boolean;
constructor(private root: any) {
if (root.setImmediate && typeof root.setImmediate === 'function') {
this.setImmediate = root.setImmediate.bind(root);
this.clearImmediate = root.clearImmediate.bind(root);
} else {
this.nextHandle = 1;
this.tasksByHandle = {};
this.currentlyRunningATask = false;
// Don't get fooled by e.g. browserify environments.
if (this.canUseProcessNextTick()) {
// For Node.js before 0.9
this.setImmediate = this.createProcessNextTickSetImmediate();
} else if (this.canUsePostMessage()) {
// For non-IE10 modern browsers
this.setImmediate = this.createPostMessageSetImmediate();
} else if (this.canUseMessageChannel()) {
// For web workers, where supported
this.setImmediate = this.createMessageChannelSetImmediate();
} else if (this.canUseReadyStateChange()) {
// For IE 68
this.setImmediate = this.createReadyStateChangeSetImmediate();
} else {
// For older browsers
this.setImmediate = this.createSetTimeoutSetImmediate();
}
let ci = function clearImmediate(handle: any) {
delete (<any>clearImmediate).instance.tasksByHandle[handle];
};
(<any>ci).instance = this;
this.clearImmediate = ci;
}
}
canUseProcessNextTick() {
return this.identify(this.root.process) === '[object process]';
}
canUseMessageChannel() {
return Boolean(this.root.MessageChannel);
}
canUseReadyStateChange() {
const document = this.root.document;
return Boolean(document && 'onreadystatechange' in document.createElement('script'));
}
canUsePostMessage() {
const root = this.root;
// The test against `importScripts` prevents this implementation from being installed inside a web worker,
// where `root.postMessage` means something completely different and can't be used for this purpose.
if (root.postMessage && !root.importScripts) {
let postMessageIsAsynchronous = true;
let oldOnMessage = root.onmessage;
root.onmessage = function() {
postMessageIsAsynchronous = false;
};
root.postMessage('', '*');
root.onmessage = oldOnMessage;
return postMessageIsAsynchronous;
}
return false;
}
// This function accepts the same arguments as setImmediate, but
// returns a function that requires no arguments.
partiallyApplied(handler: any, ...args: any[]) {
let fn = function result () {
const { handler, args } = <any>result;
if (typeof handler === 'function') {
handler.apply(undefined, args);
} else {
(new Function('' + handler))();
}
};
(<any>fn).handler = handler;
(<any>fn).args = args;
return fn;
}
addFromSetImmediateArguments(args: any[]) {
this.tasksByHandle[this.nextHandle] = this.partiallyApplied.apply(undefined, args);
return this.nextHandle++;
}
createProcessNextTickSetImmediate() {
let fn = function setImmediate() {
const { instance } = (<any>setImmediate);
let handle = instance.addFromSetImmediateArguments(arguments);
instance.root.process.nextTick(instance.partiallyApplied(instance.runIfPresent, handle));
return handle;
};
(<any>fn).instance = this;
return fn;
}
createPostMessageSetImmediate() {
// Installs an event handler on `global` for the `message` event: see
// * https://developer.mozilla.org/en/DOM/window.postMessage
// * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
const root = this.root;
let messagePrefix = 'setImmediate$' + root.Math.random() + '$';
let onGlobalMessage = function globalMessageHandler(event: any) {
const instance = (<any>globalMessageHandler).instance;
if (event.source === root &&
typeof event.data === 'string' &&
event.data.indexOf(messagePrefix) === 0) {
instance.runIfPresent(+event.data.slice(messagePrefix.length));
}
};
(<any>onGlobalMessage).instance = this;
root.addEventListener('message', onGlobalMessage, false);
let fn = function setImmediate() {
const { messagePrefix, instance } = (<any>setImmediate);
let handle = instance.addFromSetImmediateArguments(arguments);
instance.root.postMessage(messagePrefix + handle, '*');
return handle;
};
(<any>fn).instance = this;
(<any>fn).messagePrefix = messagePrefix;
return fn;
}
runIfPresent(handle: any) {
// From the spec: 'Wait until any invocations of this algorithm started before this one have completed.'
// So if we're currently running a task, we'll need to delay this invocation.
if (this.currentlyRunningATask) {
// Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
// 'too much recursion' error.
this.root.setTimeout(this.partiallyApplied(this.runIfPresent, handle), 0);
} else {
let task = this.tasksByHandle[handle];
if (task) {
this.currentlyRunningATask = true;
try {
task();
} finally {
this.clearImmediate(handle);
this.currentlyRunningATask = false;
}
}
}
}
createMessageChannelSetImmediate() {
let channel = new this.root.MessageChannel();
channel.port1.onmessage = (event: any) => {
let handle = event.data;
this.runIfPresent(handle);
};
let fn = function setImmediate() {
const { channel, instance } = (<any>setImmediate);
let handle = instance.addFromSetImmediateArguments(arguments);
channel.port2.postMessage(handle);
return handle;
};
(<any>fn).channel = channel;
(<any>fn).instance = this;
return fn;
}
createReadyStateChangeSetImmediate() {
let fn = function setImmediate() {
const instance = (<any>setImmediate).instance;
const root = instance.root;
const doc = root.document;
const html = doc.documentElement;
let handle = instance.addFromSetImmediateArguments(arguments);
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
let script = doc.createElement('script');
script.onreadystatechange = () => {
instance.runIfPresent(handle);
script.onreadystatechange = null;
html.removeChild(script);
script = null;
};
html.appendChild(script);
return handle;
};
(<any>fn).instance = this;
return fn;
}
createSetTimeoutSetImmediate() {
let fn = function setImmediate() {
const instance = (<any>setImmediate).instance;
let handle = instance.addFromSetImmediateArguments(arguments);
instance.root.setTimeout(instance.partiallyApplied(instance.runIfPresent, handle), 0);
return handle;
};
(<any>fn).instance = this;
return fn;
}
}
export const Immediate = new ImmediateDefinition(root);
+4
View File
@@ -0,0 +1,4 @@
import { root } from './root';
import { MapPolyfill } from './MapPolyfill';
export const Map = root.Map || (() => MapPolyfill)();
+43
View File
@@ -0,0 +1,43 @@
export class MapPolyfill {
public size = 0;
private _values: any[] = [];
private _keys: any[] = [];
get(key: any) {
const i = this._keys.indexOf(key);
return i === -1 ? undefined : this._values[i];
}
set(key: any, value: any) {
const i = this._keys.indexOf(key);
if (i === -1) {
this._keys.push(key);
this._values.push(value);
this.size++;
} else {
this._values[i] = value;
}
return this;
}
delete(key: any): boolean {
const i = this._keys.indexOf(key);
if (i === -1) { return false; }
this._values.splice(i, 1);
this._keys.splice(i, 1);
this.size--;
return true;
}
clear(): void {
this._keys.length = 0;
this._values.length = 0;
this.size = 0;
}
forEach(cb: Function, thisArg: any): void {
for (let i = 0; i < this.size; i++) {
cb.call(thisArg, this._values[i], this._keys[i]);
}
}
}
+17
View File
@@ -0,0 +1,17 @@
/**
* An error thrown when an action is invalid because the object has been
* unsubscribed.
*
* @see {@link Subject}
* @see {@link BehaviorSubject}
*
* @class ObjectUnsubscribedError
*/
export class ObjectUnsubscribedError extends Error {
constructor() {
const err: any = super('object unsubscribed');
(<any> this).name = err.name = 'ObjectUnsubscribedError';
(<any> this).stack = err.stack;
(<any> this).message = err.message;
}
}
+40
View File
@@ -0,0 +1,40 @@
import { root } from './root';
export interface ISetCtor {
new<T>(): ISet<T>;
}
export interface ISet<T> {
add(value: T): void;
has(value: T): boolean;
size: number;
clear(): void;
}
export function minimalSetImpl<T>(): ISetCtor {
// THIS IS NOT a full impl of Set, this is just the minimum
// bits of functionality we need for this library.
return class MinimalSet<T> implements ISet<T> {
private _values: T[] = [];
add(value: T): void {
if (!this.has(value)) {
this._values.push(value);
}
}
has(value: T): boolean {
return this._values.indexOf(value) !== -1;
}
get size(): number {
return this._values.length;
}
clear(): void {
this._values.length = 0;
}
};
}
export const Set: ISetCtor = root.Set || minimalSetImpl();
+15
View File
@@ -0,0 +1,15 @@
/**
* An error thrown when duetime elapses.
*
* @see {@link timeout}
*
* @class TimeoutError
*/
export class TimeoutError extends Error {
constructor() {
const err: any = super('Timeout has occurred');
(<any> this).name = err.name = 'TimeoutError';
(<any> this).stack = err.stack;
(<any> this).message = err.message;
}
}
+15
View File
@@ -0,0 +1,15 @@
/**
* An error thrown when one or more errors have occurred during the
* `unsubscribe` of a {@link Subscription}.
*/
export class UnsubscriptionError extends Error {
constructor(public errors: any[]) {
super();
const err: any = Error.call(this, errors ?
`${errors.length} errors occurred during unsubscription:
${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n ')}` : '');
(<any> this).name = err.name = 'UnsubscriptionError';
(<any> this).stack = err.stack;
(<any> this).message = err.message;
}
}
+10
View File
@@ -0,0 +1,10 @@
export function applyMixins(derivedCtor: any, baseCtors: any[]) {
for (let i = 0, len = baseCtors.length; i < len; i++) {
const baseCtor = baseCtors[i];
const propertyKeys = Object.getOwnPropertyNames(baseCtor.prototype);
for (let j = 0, len2 = propertyKeys.length; j < len2; j++) {
const name = propertyKeys[j];
derivedCtor.prototype[name] = baseCtor.prototype[name];
}
}
}
+20
View File
@@ -0,0 +1,20 @@
import { root } from './root';
export function assignImpl(target: Object, ...sources: Object[]) {
const len = sources.length;
for (let i = 0; i < len; i++) {
const source = sources[i];
for (let k in source) {
if (source.hasOwnProperty(k)) {
target[k] = source[k];
}
}
}
return target;
};
export function getAssign(root: any) {
return root.Object.assign || assignImpl;
}
export const assign = getAssign(root);
+2
View File
@@ -0,0 +1,2 @@
// typeof any so that it we don't have to cast when comparing a result to the error object
export const errorObject: any = { e: {} };
+3
View File
@@ -0,0 +1,3 @@
export function identity<T>(x: T): T {
return x;
}
+1
View File
@@ -0,0 +1 @@
export const isArray = Array.isArray || (<T>(x: any): x is T[] => x && typeof x.length === 'number');
+1
View File
@@ -0,0 +1 @@
export const isArrayLike = (<T>(x: any): x is ArrayLike<T> => x && typeof x.length === 'number');
+3
View File
@@ -0,0 +1,3 @@
export function isDate(value: any): value is Date {
return value instanceof Date && !isNaN(+value);
}
+3
View File
@@ -0,0 +1,3 @@
export function isFunction(x: any): x is Function {
return typeof x === 'function';
}
+9
View File
@@ -0,0 +1,9 @@
import { isArray } from '../util/isArray';
export function isNumeric(val: any): val is number {
// parseFloat NaNs numeric-cast false positives (null|true|false|"")
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
// subtraction forces infinities to NaN
// adding 1 corrects loss of precision from parseFloat (#15100)
return !isArray(val) && (val - parseFloat(val) + 1) >= 0;
};
+3
View File
@@ -0,0 +1,3 @@
export function isObject(x: any): x is Object {
return x != null && typeof x === 'object';
}
+3
View File
@@ -0,0 +1,3 @@
export function isPromise<T>(value: any | Promise<T>): value is Promise<T> {
return value && typeof (<any>value).subscribe !== 'function' && typeof (value as any).then === 'function';
}
+4
View File
@@ -0,0 +1,4 @@
import { Scheduler } from '../Scheduler';
export function isScheduler(value: any): value is Scheduler {
return value && typeof (<any>value).schedule === 'function';
}
+2
View File
@@ -0,0 +1,2 @@
/* tslint:disable:no-empty */
export function noop() { }
+8
View File
@@ -0,0 +1,8 @@
export function not(pred: Function, thisArg: any): Function {
function notPred(): any {
return !((<any> notPred).pred.apply((<any> notPred).thisArg, arguments));
}
(<any> notPred).pred = pred;
(<any> notPred).thisArg = thisArg;
return notPred;
}
+34
View File
@@ -0,0 +1,34 @@
import { noop } from './noop';
import { UnaryFunction } from '../interfaces';
/* tslint:disable:max-line-length */
export function pipe<T>(): UnaryFunction<T, T>;
export function pipe<T, A>(op1: UnaryFunction<T, A>): UnaryFunction<T, A>;
export function pipe<T, A, B>(op1: UnaryFunction<T, A>, op2: UnaryFunction<A, B>): UnaryFunction<T, B>;
export function pipe<T, A, B, C>(op1: UnaryFunction<T, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>): UnaryFunction<T, C>;
export function pipe<T, A, B, C, D>(op1: UnaryFunction<T, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>): UnaryFunction<T, D>;
export function pipe<T, A, B, C, D, E>(op1: UnaryFunction<T, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>): UnaryFunction<T, E>;
export function pipe<T, A, B, C, D, E, F>(op1: UnaryFunction<T, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>): UnaryFunction<T, F>;
export function pipe<T, A, B, C, D, E, F, G>(op1: UnaryFunction<T, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>): UnaryFunction<T, G>;
export function pipe<T, A, B, C, D, E, F, G, H>(op1: UnaryFunction<T, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>): UnaryFunction<T, H>;
export function pipe<T, A, B, C, D, E, F, G, H, I>(op1: UnaryFunction<T, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>, op9: UnaryFunction<H, I>): UnaryFunction<T, I>;
/* tslint:enable:max-line-length */
export function pipe<T, R>(...fns: Array<UnaryFunction<T, R>>): UnaryFunction<T, R> {
return pipeFromArray(fns);
}
/* @internal */
export function pipeFromArray<T, R>(fns: Array<UnaryFunction<T, R>>): UnaryFunction<T, R> {
if (!fns) {
return noop as UnaryFunction<any, any>;
}
if (fns.length === 1) {
return fns[0];
}
return function piped(input: T): R {
return fns.reduce((prev: any, fn: UnaryFunction<T, R>) => fn(prev), input);
};
}
+31
View File
@@ -0,0 +1,31 @@
declare let global: any;
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
declare var WorkerGlobalScope: any;
// CommonJS / Node have global context exposed as "global" variable.
// We don't want to include the whole node.d.ts this this compilation unit so we'll just fake
// the global "global" var for now.
const __window = typeof window !== 'undefined' && window;
const __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
self instanceof WorkerGlobalScope && self;
const __global = typeof global !== 'undefined' && global;
const _root: any = __window || __global || __self;
// Workaround Closure Compiler restriction: The body of a goog.module cannot use throw.
// This is needed when used with angular/tsickle which inserts a goog.module statement.
// Wrap in IIFE
(function () {
if (!_root) {
throw new Error('RxJS could not find any global context (window, self, global)');
}
})();
export { _root as root };
+85
View File
@@ -0,0 +1,85 @@
import { root } from './root';
import { isArrayLike } from './isArrayLike';
import { isPromise } from './isPromise';
import { isObject } from './isObject';
import { Subscriber } from '../Subscriber';
import { Observable, ObservableInput } from '../Observable';
import { iterator as Symbol_iterator } from '../symbol/iterator';
import { Subscription } from '../Subscription';
import { InnerSubscriber } from '../InnerSubscriber';
import { OuterSubscriber } from '../OuterSubscriber';
import { observable as Symbol_observable } from '../symbol/observable';
export function subscribeToResult<T, R>(outerSubscriber: OuterSubscriber<T, R>,
result: any,
outerValue?: T,
outerIndex?: number): Subscription;
export function subscribeToResult<T>(outerSubscriber: OuterSubscriber<any, any>,
result: ObservableInput<T>,
outerValue?: T,
outerIndex?: number): Subscription {
let destination: Subscriber<any> = new InnerSubscriber(outerSubscriber, outerValue, outerIndex);
if (destination.closed) {
return null;
}
if (result instanceof Observable) {
if (result._isScalar) {
destination.next((<any>result).value);
destination.complete();
return null;
} else {
destination.syncErrorThrowable = true;
return result.subscribe(destination);
}
} else if (isArrayLike(result)) {
for (let i = 0, len = result.length; i < len && !destination.closed; i++) {
destination.next(result[i]);
}
if (!destination.closed) {
destination.complete();
}
} else if (isPromise(result)) {
result.then(
(value) => {
if (!destination.closed) {
destination.next(<any>value);
destination.complete();
}
},
(err: any) => destination.error(err)
)
.then(null, (err: any) => {
// Escaping the Promise trap: globally throw unhandled errors
root.setTimeout(() => { throw err; });
});
return destination;
} else if (result && typeof result[Symbol_iterator] === 'function') {
const iterator = <any>result[Symbol_iterator]();
do {
let item = iterator.next();
if (item.done) {
destination.complete();
break;
}
destination.next(item.value);
if (destination.closed) {
break;
}
} while (true);
} else if (result && typeof result[Symbol_observable] === 'function') {
const obs = result[Symbol_observable]();
if (typeof obs.subscribe !== 'function') {
destination.error(new TypeError('Provided object does not correctly implement Symbol.observable'));
} else {
return obs.subscribe(new InnerSubscriber(outerSubscriber, outerValue, outerIndex));
}
} else {
const value = isObject(result) ? 'an invalid object' : `'${result}'`;
const msg = `You provided ${value} where a stream was expected.`
+ ' You can provide an Observable, Promise, Array, or Iterable.';
destination.error(new TypeError(msg));
}
return null;
}
+25
View File
@@ -0,0 +1,25 @@
import { Subscriber } from '../Subscriber';
import { rxSubscriber as rxSubscriberSymbol } from '../symbol/rxSubscriber';
import { PartialObserver, empty as emptyObserver } from '../Observer';
export function toSubscriber<T>(
nextOrObserver?: PartialObserver<T> | ((value: T) => void),
error?: (error: any) => void,
complete?: () => void): Subscriber<T> {
if (nextOrObserver) {
if (nextOrObserver instanceof Subscriber) {
return (<Subscriber<T>> nextOrObserver);
}
if (nextOrObserver[rxSubscriberSymbol]) {
return nextOrObserver[rxSubscriberSymbol]();
}
}
if (!nextOrObserver && !error && !complete) {
return new Subscriber(emptyObserver);
}
return new Subscriber(nextOrObserver, error, complete);
}
+17
View File
@@ -0,0 +1,17 @@
import { errorObject } from './errorObject';
let tryCatchTarget: Function;
function tryCatcher(this: any): any {
try {
return tryCatchTarget.apply(this, arguments);
} catch (e) {
errorObject.e = e;
return errorObject;
}
}
export function tryCatch<T extends Function>(fn: T): T {
tryCatchTarget = fn;
return <any>tryCatcher;
};