new license file version [CI SKIP]

This commit is contained in:
2023-03-15 13:43:57 +00:00
parent d8a3063735
commit 00359d25c1
5600 changed files with 523898 additions and 2 deletions

View File

@@ -0,0 +1,68 @@
import { Observable } from '../Observable';
import { SchedulerLike } from '../types';
/**
* The same Observable instance returned by any call to {@link empty} without a
* `scheduler`. It is preferrable to use this over `empty()`.
*/
export const EMPTY = new Observable<never>(subscriber => subscriber.complete());
/**
* Creates an Observable that emits no items to the Observer and immediately
* emits a complete notification.
*
* <span class="informal">Just emits 'complete', and nothing else.
* </span>
*
* ![](empty.png)
*
* This static operator is useful for creating a simple Observable that only
* emits the complete notification. It can be used for composing with other
* Observables, such as in a {@link mergeMap}.
*
* ## Examples
* ### Emit the number 7, then complete
* ```ts
* import { empty } from 'rxjs';
* import { startWith } from 'rxjs/operators';
*
* const result = empty().pipe(startWith(7));
* result.subscribe(x => console.log(x));
* ```
*
* ### Map and flatten only odd numbers to the sequence 'a', 'b', 'c'
* ```ts
* import { empty, interval, of } from 'rxjs';
* import { mergeMap } from 'rxjs/operators';
*
* const interval$ = interval(1000);
* const result = interval$.pipe(
* mergeMap(x => x % 2 === 1 ? of('a', 'b', 'c') : empty()),
* );
* result.subscribe(x => console.log(x));
*
* // Results in the following to the console:
* // x is equal to the count on the interval eg(0,1,2,3,...)
* // x will occur every 1000ms
* // if x % 2 is equal to 1 print abc
* // if x % 2 is not equal to 1 nothing will be output
* ```
*
* @see {@link Observable}
* @see {@link never}
* @see {@link of}
* @see {@link throwError}
*
* @param scheduler A {@link SchedulerLike} to use for scheduling
* the emission of the complete notification.
* @return An "empty" Observable: emits only the complete
* notification.
* @deprecated Deprecated in favor of using {@link EMPTY} constant, or {@link scheduled} (e.g. `scheduled([], scheduler)`)
*/
export function empty(scheduler?: SchedulerLike) {
return scheduler ? emptyScheduled(scheduler) : EMPTY;
}
function emptyScheduled(scheduler: SchedulerLike) {
return new Observable<never>(subscriber => scheduler.schedule(() => subscriber.complete()));
}

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ObjectUnsubscribedErrorImpl = (function () {
function ObjectUnsubscribedErrorImpl() {
Error.call(this);
this.message = 'object unsubscribed';
this.name = 'ObjectUnsubscribedError';
return this;
}
ObjectUnsubscribedErrorImpl.prototype = Object.create(Error.prototype);
return ObjectUnsubscribedErrorImpl;
})();
exports.ObjectUnsubscribedError = ObjectUnsubscribedErrorImpl;
//# sourceMappingURL=ObjectUnsubscribedError.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throttleTime.js","sources":["../../../src/internal/operators/throttleTime.ts"],"names":[],"mappings":"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"}

View File

@@ -0,0 +1,6 @@
/**
* Throws an error on another job so that it's picked up by the runtime's
* uncaught error handling mechanism.
* @param err the error to throw
*/
export declare function hostReportError(err: any): void;

View File

@@ -0,0 +1 @@
module.exports={A:{A:{"1":"G A B","2":"J E F BC"},B:{"1":"C K L H M N O P Q R S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t"},C:{"1":"0 1 2 3 4 5 6 7 8 9 H M N O v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t xB yB","2":"CC tB I u J E F G A B C K L DC EC"},D:{"1":"6 7 8 9 AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t xB yB FC","132":"0 1 2 3 4 5 I u J E F G A B C K L H M N O v w x y z"},E:{"1":"E F G A B C K L H IC JC KC 0B qB rB 1B LC MC 2B 3B 4B 5B sB 6B 7B 8B NC","16":"J GC zB","132":"I u HC"},F:{"1":"0 1 2 3 4 5 6 7 8 9 N O v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d rB","2":"G B OC PC QC RC qB 9B SC","16":"C","132":"H M"},G:{"1":"F XC YC ZC aC bC cC dC eC fC gC hC iC jC kC lC mC 2B 3B 4B 5B sB 6B 7B 8B","16":"zB TC AC","132":"UC VC WC"},H:{"2":"nC"},I:{"1":"D sC tC","16":"oC pC","132":"tB I qC rC AC"},J:{"132":"E A"},K:{"1":"e rB","2":"A B qB 9B","16":"C"},L:{"1":"D"},M:{"1":"D"},N:{"1":"A B"},O:{"1":"uC"},P:{"1":"I vC wC xC yC zC 0B 0C 1C 2C 3C 4C sB 5C 6C 7C"},Q:{"1":"1B"},R:{"1":"8C"},S:{"1":"9C"}},B:5,C:"KeyboardEvent.location"};

View File

@@ -0,0 +1,12 @@
/** PURE_IMPORTS_START _util_not,_util_subscribeTo,_operators_filter,_Observable PURE_IMPORTS_END */
import { not } from '../util/not';
import { subscribeTo } from '../util/subscribeTo';
import { filter } from '../operators/filter';
import { Observable } from '../Observable';
export function partition(source, predicate, thisArg) {
return [
filter(predicate, thisArg)(new Observable(subscribeTo(source))),
filter(not(predicate, thisArg))(new Observable(subscribeTo(source)))
];
}
//# sourceMappingURL=partition.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"interval.js","sources":["../../src/internal/observable/interval.ts"],"names":[],"mappings":";;AAAA,4CAA2C;AAC3C,4CAA2C;AAE3C,+CAA8C;AAmD9C,SAAgB,QAAQ,CAAC,MAAU,EACV,SAAgC;IADhC,uBAAA,EAAA,UAAU;IACV,0BAAA,EAAA,YAA2B,aAAK;IACvD,IAAI,CAAC,qBAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE;QACpC,MAAM,GAAG,CAAC,CAAC;KACZ;IAED,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,CAAC,QAAQ,KAAK,UAAU,EAAE;QAC1D,SAAS,GAAG,aAAK,CAAC;KACnB;IAED,OAAO,IAAI,uBAAU,CAAS,UAAA,UAAU;QACtC,UAAU,CAAC,GAAG,CACZ,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,UAAU,YAAA,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,QAAA,EAAE,CAAC,CACzE,CAAC;QACF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC;AAhBD,4BAgBC;AAED,SAAS,QAAQ,CAAuC,KAAoB;IAClE,IAAA,6BAAU,EAAE,uBAAO,EAAE,qBAAM,CAAW;IAC9C,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,IAAI,CAAC,QAAQ,CAAC,EAAE,UAAU,YAAA,EAAE,OAAO,EAAE,OAAO,GAAG,CAAC,EAAE,MAAM,QAAA,EAAE,EAAE,MAAM,CAAC,CAAC;AACtE,CAAC"}

View File

@@ -0,0 +1 @@
module.exports={A:{A:{"1":"A B","2":"J E F G BC"},B:{"1":"C K L H M N O P Q R S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t"},C:{"1":"0 1 2 3 4 5 6 7 8 9 CC tB I u J E F G A B C K L H M N O v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t xB yB DC EC"},D:{"1":"0 1 2 3 4 5 6 7 8 9 G A B C K L H M N O v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R S T U V W X Y Z a b c d f g h i j k l m n o p q r s D t xB yB FC","2":"I u J E F"},E:{"1":"J E F G A B C K L H HC IC JC KC 0B qB rB 1B LC MC 2B 3B 4B 5B sB 6B 7B 8B NC","2":"I u GC zB"},F:{"1":"0 1 2 3 4 5 6 7 8 9 B C H M N O v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB e lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d QC RC qB 9B SC rB","2":"G OC PC"},G:{"4":"F zB TC AC UC VC WC XC YC ZC aC bC cC dC eC fC gC hC iC jC kC lC mC 2B 3B 4B 5B sB 6B 7B 8B"},H:{"4":"nC"},I:{"4":"tB I D oC pC qC rC AC sC tC"},J:{"1":"A","4":"E"},K:{"4":"A B C e qB 9B rB"},L:{"4":"D"},M:{"4":"D"},N:{"4":"A B"},O:{"4":"uC"},P:{"4":"I vC wC xC yC zC 0B 0C 1C 2C 3C 4C sB 5C 6C 7C"},Q:{"1":"1B"},R:{"4":"8C"},S:{"2":"9C"}},B:1,C:"Spellcheck attribute"};

View File

@@ -0,0 +1,101 @@
import { Observable } from '../Observable';
import { SchedulerAction, SchedulerLike } from '../types';
import { async } from '../scheduler/async';
import { isNumeric } from '../util/isNumeric';
import { isScheduler } from '../util/isScheduler';
import { Subscriber } from '../Subscriber';
/**
* Creates an Observable that starts emitting after an `dueTime` and
* emits ever increasing numbers after each `period` of time thereafter.
*
* <span class="informal">Its like {@link index/interval}, but you can specify when
* should the emissions start.</span>
*
* ![](timer.png)
*
* `timer` returns an Observable that emits an infinite sequence of ascending
* integers, with a constant interval of time, `period` of your choosing
* between those emissions. The first emission happens after the specified
* `dueTime`. The initial delay may be a `Date`. By default, this
* operator uses the {@link asyncScheduler} {@link SchedulerLike} to provide a notion of time, but you
* may pass any {@link SchedulerLike} to it. If `period` is not specified, the output
* Observable emits only one value, `0`. Otherwise, it emits an infinite
* sequence.
*
* ## Examples
* ### Emits ascending numbers, one every second (1000ms), starting after 3 seconds
* ```ts
* import { timer } from 'rxjs';
*
* const numbers = timer(3000, 1000);
* numbers.subscribe(x => console.log(x));
* ```
*
* ### Emits one number after five seconds
* ```ts
* import { timer } from 'rxjs';
*
* const numbers = timer(5000);
* numbers.subscribe(x => console.log(x));
* ```
* @see {@link index/interval}
* @see {@link delay}
*
* @param {number|Date} [dueTime] The initial delay time specified as a Date object or as an integer denoting
* milliseconds to wait before emitting the first value of 0`.
* @param {number|SchedulerLike} [periodOrScheduler] The period of time between emissions of the
* subsequent numbers.
* @param {SchedulerLike} [scheduler=async] The {@link SchedulerLike} to use for scheduling
* the emission of values, and providing a notion of "time".
* @return {Observable} An Observable that emits a `0` after the
* `dueTime` and ever increasing numbers after each `period` of time
* thereafter.
* @static true
* @name timer
* @owner Observable
*/
export function timer(dueTime: number | Date = 0,
periodOrScheduler?: number | SchedulerLike,
scheduler?: SchedulerLike): Observable<number> {
let period = -1;
if (isNumeric(periodOrScheduler)) {
period = Number(periodOrScheduler) < 1 && 1 || Number(periodOrScheduler);
} else if (isScheduler(periodOrScheduler)) {
scheduler = periodOrScheduler as any;
}
if (!isScheduler(scheduler)) {
scheduler = async;
}
return new Observable(subscriber => {
const due = isNumeric(dueTime)
? (dueTime as number)
: (+dueTime - scheduler.now());
return scheduler.schedule(dispatch, due, {
index: 0, period, subscriber
});
});
}
interface TimerState {
index: number;
period: number;
subscriber: Subscriber<number>;
}
function dispatch(this: SchedulerAction<TimerState>, state: TimerState) {
const { index, period, subscriber } = state;
subscriber.next(index);
if (subscriber.closed) {
return;
} else if (period === -1) {
return subscriber.complete();
}
state.index = index + 1;
this.schedule(state, period);
}

View File

@@ -0,0 +1 @@
{"version":3,"file":"debounceTime.js","sources":["../../../src/internal/operators/debounceTime.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAuD3C,MAAM,UAAU,YAAY,CAAI,OAAe,EAAE,SAAgC;IAAhC,0BAAA,EAAA,iBAAgC;IAC/E,OAAO,UAAC,MAAqB,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,IAAI,oBAAoB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,EAAzD,CAAyD,CAAC;AAC9F,CAAC;AAED;IACE,8BAAoB,OAAe,EAAU,SAAwB;QAAjD,YAAO,GAAP,OAAO,CAAQ;QAAU,cAAS,GAAT,SAAS,CAAe;IACrE,CAAC;IAED,mCAAI,GAAJ,UAAK,UAAyB,EAAE,MAAW;QACzC,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,sBAAsB,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAChG,CAAC;IACH,2BAAC;AAAD,CAAC,AAPD,IAOC;AAOD;IAAwC,kDAAa;IAKnD,gCAAY,WAA0B,EAClB,OAAe,EACf,SAAwB;QAF5C,YAGE,kBAAM,WAAW,CAAC,SACnB;QAHmB,aAAO,GAAP,OAAO,CAAQ;QACf,eAAS,GAAT,SAAS,CAAe;QANpC,2BAAqB,GAAiB,IAAI,CAAC;QAC3C,eAAS,GAAM,IAAI,CAAC;QACpB,cAAQ,GAAY,KAAK,CAAC;;IAMlC,CAAC;IAES,sCAAK,GAAf,UAAgB,KAAQ;QACtB,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IACnG,CAAC;IAES,0CAAS,GAAnB;QACE,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED,8CAAa,GAAb;QACE,IAAI,CAAC,aAAa,EAAE,CAAC;QAErB,IAAI,IAAI,CAAC,QAAQ,EAAE;YACT,IAAA,0BAAS,CAAU;YAM3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;YACtB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAClC;IACH,CAAC;IAEO,8CAAa,GAArB;QACE,IAAM,qBAAqB,GAAG,IAAI,CAAC,qBAAqB,CAAC;QAEzD,IAAI,qBAAqB,KAAK,IAAI,EAAE;YAClC,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;YACnC,qBAAqB,CAAC,WAAW,EAAE,CAAC;YACpC,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;SACnC;IACH,CAAC;IACH,6BAAC;AAAD,CAAC,AAhDD,CAAwC,UAAU,GAgDjD;AAED,SAAS,YAAY,CAAC,UAAuC;IAC3D,UAAU,CAAC,aAAa,EAAE,CAAC;AAC7B,CAAC"}

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env node
const updater = require('update-notifier');
const parseArgs = require('yargs-parser');
const pkg = require('../package.json');
const release = require('../lib');
const aliases = {
c: 'config',
d: 'dry-run',
h: 'help',
i: 'increment',
v: 'version',
V: 'verbose'
};
const parseCliArguments = args => {
const options = parseArgs(args, {
boolean: ['dry-run', 'ci'],
alias: aliases,
configuration: {
'parse-numbers': false,
'camel-case-expansion': false
}
});
if (options.V) {
options.verbose = typeof options.V === 'boolean' ? options.V : options.V.length;
delete options.V;
}
options.increment = options._[0] || options.i;
return options;
};
const options = parseCliArguments([].slice.call(process.argv, 2));
updater({ pkg: pkg }).notify();
release(options).then(
() => process.exit(0),
() => process.exit(1)
);

View File

@@ -0,0 +1 @@
{"version":3,"file":"map.js","sources":["../src/operator/map.ts"],"names":[],"mappings":";;;;;AAAA,8CAAyC"}

View File

@@ -0,0 +1 @@
{"version":3,"file":"repeat.js","sources":["../../../src/internal/operators/repeat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AA2D5C,MAAM,UAAU,MAAM,CAAI,QAAgB,CAAC,CAAC;IAC1C,OAAO,CAAC,MAAqB,EAAE,EAAE;QAC/B,IAAI,KAAK,KAAK,CAAC,EAAE;YACf,OAAO,KAAK,EAAE,CAAC;SAChB;aAAM,IAAI,KAAK,GAAG,CAAC,EAAE;YACpB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;SACpD;aAAM;YACL,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;SAC3D;IACH,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,cAAc;IAClB,YAAoB,KAAa,EACb,MAAqB;QADrB,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAe;IACzC,CAAC;IACD,IAAI,CAAC,UAAyB,EAAE,MAAW;QACzC,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACrF,CAAC;CACF;AAOD,MAAM,gBAAoB,SAAQ,UAAa;IAC7C,YAAY,WAA4B,EACpB,KAAa,EACb,MAAqB;QACvC,KAAK,CAAC,WAAW,CAAC,CAAC;QAFD,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAe;IAEzC,CAAC;IACD,QAAQ;QACN,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;YAC/B,IAAI,KAAK,KAAK,CAAC,EAAE;gBACf,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;aACzB;iBAAM,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;gBACrB,IAAI,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC;aACxB;YACD,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC,CAAC;SACjD;IACH,CAAC;CACF"}

View File

@@ -0,0 +1,48 @@
{
"name": "mocha",
"homepage": "https://mochajs.org",
"description": "simple, flexible, fun test framework",
"repository": {
"type": "git",
"url": "git://github.com/mochajs/mocha.git"
},
"main": [
"mocha.js",
"mocha.css"
],
"ignore": [
"bin",
"editors",
"images",
"lib",
"scripts",
"test",
"assets",
"media",
".*",
"index.js",
"karma.conf.js",
"browser-entry.js",
"Makefile",
"package.json",
"appveyor.yml"
],
"keywords": [
"mocha",
"test",
"bdd",
"tdd",
"tap"
],
"license": "MIT",
"version": "3.4.2",
"_release": "3.4.2",
"_resolution": {
"type": "version",
"tag": "v3.4.2",
"commit": "800963464bc4e0e09c2e85e8a9edd8d20a0bbf57"
},
"_source": "https://github.com/mochajs/mocha.git",
"_target": "~3.4.2",
"_originalSource": "mocha"
}

View File

@@ -0,0 +1 @@
module.exports={C:{"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0.03869,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0.00553,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0.01105,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0.00553,"77":0,"78":0.03869,"79":0,"80":0,"81":0,"82":0,"83":0.00553,"84":0.00553,"85":0,"86":0,"87":0,"88":0.01105,"89":0.00553,"90":0,"91":0.00553,"92":0.01105,"93":0,"94":0,"95":0,"96":0.01105,"97":0.00553,"98":0,"99":0.00553,"100":0.01105,"101":0,"102":0.05527,"103":0.01105,"104":0.00553,"105":0.01105,"106":0.02211,"107":0.06632,"108":2.4153,"109":1.22699,"110":0.00553,"111":0,"3.5":0,"3.6":0},D:{"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0.02211,"50":0,"51":0.01658,"52":0,"53":0.00553,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0.01105,"74":0,"75":0,"76":0.00553,"77":0,"78":0.01658,"79":0.02211,"80":0.00553,"81":0.00553,"83":0.00553,"84":0.00553,"85":0.01105,"86":0.01105,"87":0.03869,"88":0.00553,"89":0.00553,"90":0.00553,"91":0.01105,"92":0.02211,"93":0,"94":0.00553,"95":0.00553,"96":0.00553,"97":0.03316,"98":0.01658,"99":0.01105,"100":0.01658,"101":0.00553,"102":0.02211,"103":0.06632,"104":0.06632,"105":0.04974,"106":0.06632,"107":0.19345,"108":9.88228,"109":9.44564,"110":0.00553,"111":0,"112":0},F:{"9":0,"11":0,"12":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0.01658,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0.00553,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0.02211,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"60":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0.01105,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0.45874,"94":0.60797,"9.5-9.6":0,"10.0-10.1":0,"10.5":0,"10.6":0,"11.1":0,"11.5":0,"11.6":0,"12.1":0},B:{"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0.00553,"79":0,"80":0,"81":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0.01105,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0,"101":0.00553,"102":0,"103":0.00553,"104":0.00553,"105":0.01105,"106":0.00553,"107":0.04422,"108":1.48676,"109":1.55861},E:{"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0.00553,"14":0.04422,"15":0.01105,_:"0","3.1":0,"3.2":0,"5.1":0,"6.1":0,"7.1":0,"9.1":0,"10.1":0,"11.1":0,"12.1":0.00553,"13.1":0.07185,"14.1":0.12159,"15.1":0.02764,"15.2-15.3":0.02764,"15.4":0.03316,"15.5":0.06632,"15.6":0.31504,"16.0":0.08291,"16.1":0.23766,"16.2":0.34267,"16.3":0.03316},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0,"5.0-5.1":0,"6.0-6.1":0,"7.0-7.1":0,"8.1-8.4":0,"9.0-9.2":0,"9.3":0.02823,"10.0-10.2":0,"10.3":0.02419,"11.0-11.2":0.00403,"11.3-11.4":0.00403,"12.0-12.1":0.00403,"12.2-12.5":0.17541,"13.0-13.1":0.00403,"13.2":0.01008,"13.3":0.01815,"13.4-13.7":0.07863,"14.0-14.4":0.27017,"14.5-14.8":0.65929,"15.0-15.1":0.12097,"15.2-15.3":0.1613,"15.4":0.26412,"15.5":0.54437,"15.6":2.5283,"16.0":3.85898,"16.1":6.20784,"16.2":3.78438,"16.3":0.47985},P:{"4":0.11285,"5.0-5.4":0.03078,"6.2-6.4":0,"7.2-7.4":0.02052,"8.2":0,"9.2":0,"10.1":0,"11.1-11.2":0.01026,"12.0":0,"13.0":0.02052,"14.0":0.0513,"15.0":0.03078,"16.0":0.06156,"17.0":0.06156,"18.0":0.11285,"19.0":2.84179},I:{"0":0,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0.04866,"4.2-4.3":0,"4.4":0,"4.4.3-4.4.4":0.0524},K:{_:"0 10 11 12 11.1 11.5 12.1"},A:{"6":0,"7":0,"8":0,"9":0,"10":0,"11":0.03869,"5.5":0},J:{"7":0,"10":0},N:{"10":0,"11":0},S:{"2.5":0},R:{_:"0"},M:{"0":0.47861},Q:{"13.1":0},O:{"0":0.01342},H:{"0":0.18633},L:{"0":44.3418}};

View File

@@ -0,0 +1,258 @@
# localForage
[![Build Status](https://travis-ci.org/localForage/localForage.svg?branch=master)](http://travis-ci.org/localForage/localForage)
[![NPM version](https://badge.fury.io/js/localforage.svg)](http://badge.fury.io/js/localforage)
[![Dependency Status](https://img.shields.io/david/localForage/localForage.svg)](https://david-dm.org/localForage/localForage)
[![npm](https://img.shields.io/npm/dm/localforage.svg?maxAge=2592000)](https://npmcharts.com/compare/localforage?minimal=true)
[![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/localforage/badge?style=rounded)](https://www.jsdelivr.com/package/npm/localforage)
[![minzipped size](https://badgen.net/bundlephobia/minzip/localforage)](https://bundlephobia.com/result?p=localforage@1.9.0)
localForage is a fast and simple storage library for JavaScript. localForage
improves the offline experience of your web app by using asynchronous storage
(IndexedDB or WebSQL) with a simple, `localStorage`-like API.
localForage uses localStorage in browsers with no IndexedDB or
WebSQL support. See [the wiki for detailed compatibility info][supported browsers].
To use localForage, just drop a single JavaScript file into your page:
```html
<script src="localforage/dist/localforage.js"></script>
<script>localforage.getItem('something', myCallback);</script>
```
Try the [live example](http://codepen.io/thgreasi/pen/ojYKeE).
Download the [latest localForage from GitHub](https://github.com/localForage/localForage/releases/latest), or install with
[npm](https://www.npmjs.com/):
```bash
npm install localforage
```
[supported browsers]: https://github.com/localForage/localForage/wiki/Supported-Browsers-Platforms
## Support
Lost? Need help? Try the
[localForage API documentation](https://localforage.github.io/localForage). [localForage API文档也有中文版。](https://localforage.docschina.org)
If you're having trouble using the library, running the tests, or want to contribute to localForage, please look through the [existing issues](https://github.com/localForage/localForage/issues) for your problem first before creating a new one. If you still need help, [feel free to file an issue](https://github.com/localForage/localForage/issues/new).
# How to use localForage
## Callbacks vs Promises
Because localForage uses async storage, it has an async API.
It's otherwise exactly the same as the
[localStorage API](https://hacks.mozilla.org/2009/06/localstorage/).
localForage has a dual API that allows you to either use Node-style callbacks
or [Promises](https://www.promisejs.org/). If you are unsure which one is right for you, it's recommended to use Promises.
Here's an example of the Node-style callback form:
```js
localforage.setItem('key', 'value', function (err) {
// if err is non-null, we got an error
localforage.getItem('key', function (err, value) {
// if err is non-null, we got an error. otherwise, value is the value
});
});
```
And the Promise form:
```js
localforage.setItem('key', 'value').then(function () {
return localforage.getItem('key');
}).then(function (value) {
// we got our value
}).catch(function (err) {
// we got an error
});
```
Or, use `async`/`await`:
```js
try {
const value = await localforage.getItem('somekey');
// This code runs once the value has been loaded
// from the offline store.
console.log(value);
} catch (err) {
// This code runs if there were any errors.
console.log(err);
}
```
For more examples, please visit [the API docs](https://localforage.github.io/localForage).
## Storing Blobs, TypedArrays, and other JS objects
You can store any type in localForage; you aren't limited to strings like in
localStorage. Even if localStorage is your storage backend, localForage
automatically does `JSON.parse()` and `JSON.stringify()` when getting/setting
values.
localForage supports storing all native JS objects that can be serialized to
JSON, as well as ArrayBuffers, Blobs, and TypedArrays. Check the
[API docs][api] for a full list of types supported by localForage.
All types are supported in every storage backend, though storage limits in
localStorage make storing many large Blobs impossible.
[api]: https://localforage.github.io/localForage/#data-api-setitem
## Configuration
You can set database information with the `config()` method.
Available options are `driver`, `name`, `storeName`, `version`, `size`, and
`description`.
Example:
```javascript
localforage.config({
driver : localforage.WEBSQL, // Force WebSQL; same as using setDriver()
name : 'myApp',
version : 1.0,
size : 4980736, // Size of database, in bytes. WebSQL-only for now.
storeName : 'keyvaluepairs', // Should be alphanumeric, with underscores.
description : 'some description'
});
```
**Note:** you must call `config()` _before_ you interact with your data. This
means calling `config()` before using `getItem()`, `setItem()`, `removeItem()`,
`clear()`, `key()`, `keys()` or `length()`.
## Multiple instances
You can create multiple instances of localForage that point to different stores
using `createInstance`. All the configuration options used by
[`config`](#configuration) are supported.
``` javascript
var store = localforage.createInstance({
name: "nameHere"
});
var otherStore = localforage.createInstance({
name: "otherName"
});
// Setting the key on one of these doesn't affect the other.
store.setItem("key", "value");
otherStore.setItem("key", "value2");
```
## RequireJS
You can use localForage with [RequireJS](http://requirejs.org/):
```javascript
define(['localforage'], function(localforage) {
// As a callback:
localforage.setItem('mykey', 'myvalue', console.log);
// With a Promise:
localforage.setItem('mykey', 'myvalue').then(console.log);
});
```
## TypeScript
If you have the [`allowSyntheticDefaultImports` compiler option](https://www.typescriptlang.org/docs/handbook/compiler-options.html) set to `true` in your [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (supported in TypeScript v1.8+), you should use:
```javascript
import localForage from "localforage";
```
Otherwise you should use one of the following:
```javascript
import * as localForage from "localforage";
// or, in case that the typescript version that you are using
// doesn't support ES6 style imports for UMD modules like localForage
import localForage = require("localforage");
```
## Framework Support
If you use a framework listed, there's a localForage storage driver for the
models in your framework so you can store data offline with localForage. We
have drivers for the following frameworks:
* [AngularJS](https://github.com/ocombe/angular-localForage)
* [Angular 4 and up](https://github.com/Alorel/ngforage/)
* [Backbone](https://github.com/localForage/localForage-backbone)
* [Ember](https://github.com/genkgo/ember-localforage-adapter)
* [Vue](https://github.com/dmlzj/vlf)
* [NuxtJS](https://github.com/nuxt-community/localforage-module)
If you have a driver you'd like listed, please
[open an issue](https://github.com/localForage/localForage/issues/new) to have it
added to this list.
## Custom Drivers
You can create your own driver if you want; see the
[`defineDriver`](https://localforage.github.io/localForage/#driver-api-definedriver) API docs.
There is a [list of custom drivers on the wiki][custom drivers].
[custom drivers]: https://github.com/localForage/localForage/wiki/Custom-Drivers
# Working on localForage
You'll need [node/npm](http://nodejs.org/) and
[bower](http://bower.io/#installing-bower).
To work on localForage, you should start by
[forking it](https://github.com/localForage/localForage/fork) and installing its
dependencies. Replace `USERNAME` with your GitHub username and run the
following:
```bash
# Install bower globally if you don't have it:
npm install -g bower
# Replace USERNAME with your GitHub username:
git clone git@github.com:USERNAME/localForage.git
cd localForage
npm install
bower install
```
Omitting the bower dependencies will cause the tests to fail!
## Running Tests
You need PhantomJS installed to run local tests. Run `npm test` (or,
directly: `grunt test`). Your code must also pass the
[linter](http://jshint.com/).
localForage is designed to run in the browser, so the tests explicitly require
a browser environment. Local tests are run on a headless WebKit (using
[PhantomJS](http://phantomjs.org)).
When you submit a pull request, tests will be run against all browsers that
localForage supports on Travis CI using [Sauce Labs](https://saucelabs.com/).
## Library Size
As of version 1.7.3 the payload added to your app is rather small. Served using gzip compression, localForage will add less than 10k to your total bundle size:
<dl>
<dt>minified</dt><dd>`~29kB`</dd>
<dt>gzipped</dt><dd>`~8.8kB`</dd>
<dt>brotli'd</dt><dd>`~7.8kB`</dd>
</dl>
# License
This program is free software; it is distributed under an
[Apache License](https://github.com/localForage/localForage/blob/master/LICENSE).
---
Copyright (c) 2013-2016 [Mozilla](https://mozilla.org)
([Contributors](https://github.com/localForage/localForage/graphs/contributors)).

View File

@@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("rxjs-compat/add/operator/scan");
//# sourceMappingURL=scan.js.map

View File

@@ -0,0 +1,50 @@
import { Subscriber } from '../Subscriber';
import { Notification } from '../Notification';
export function observeOn(scheduler, delay = 0) {
return function observeOnOperatorFunction(source) {
return source.lift(new ObserveOnOperator(scheduler, delay));
};
}
export class ObserveOnOperator {
constructor(scheduler, delay = 0) {
this.scheduler = scheduler;
this.delay = delay;
}
call(subscriber, source) {
return source.subscribe(new ObserveOnSubscriber(subscriber, this.scheduler, this.delay));
}
}
export class ObserveOnSubscriber extends Subscriber {
constructor(destination, scheduler, delay = 0) {
super(destination);
this.scheduler = scheduler;
this.delay = delay;
}
static dispatch(arg) {
const { notification, destination } = arg;
notification.observe(destination);
this.unsubscribe();
}
scheduleMessage(notification) {
const destination = this.destination;
destination.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch, this.delay, new ObserveOnMessage(notification, this.destination)));
}
_next(value) {
this.scheduleMessage(Notification.createNext(value));
}
_error(err) {
this.scheduleMessage(Notification.createError(err));
this.unsubscribe();
}
_complete() {
this.scheduleMessage(Notification.createComplete());
this.unsubscribe();
}
}
export class ObserveOnMessage {
constructor(notification, destination) {
this.notification = notification;
this.destination = destination;
}
}
//# sourceMappingURL=observeOn.js.map

View File

@@ -0,0 +1,319 @@
import { Subscriber } from '../Subscriber';
import { Subscription } from '../Subscription';
import { Observable } from '../Observable';
import { Operator } from '../Operator';
import { Subject } from '../Subject';
import { OperatorFunction } from '../types';
/* tslint:disable:max-line-length */
export function groupBy<T, K>(keySelector: (value: T) => K): OperatorFunction<T, GroupedObservable<K, T>>;
export function groupBy<T, K>(keySelector: (value: T) => K, elementSelector: void, durationSelector: (grouped: GroupedObservable<K, T>) => Observable<any>): OperatorFunction<T, GroupedObservable<K, T>>;
export function groupBy<T, K, R>(keySelector: (value: T) => K, elementSelector?: (value: T) => R, durationSelector?: (grouped: GroupedObservable<K, R>) => Observable<any>): OperatorFunction<T, GroupedObservable<K, R>>;
export function groupBy<T, K, R>(keySelector: (value: T) => K, elementSelector?: (value: T) => R, durationSelector?: (grouped: GroupedObservable<K, R>) => Observable<any>, subjectSelector?: () => Subject<R>): OperatorFunction<T, GroupedObservable<K, R>>;
/* tslint:enable:max-line-length */
/**
* Groups the items emitted by an Observable according to a specified criterion,
* and emits these grouped items as `GroupedObservables`, one
* {@link GroupedObservable} per group.
*
* ![](groupBy.png)
*
* When the Observable emits an item, a key is computed for this item with the keySelector function.
*
* If a {@link GroupedObservable} for this key exists, this {@link GroupedObservable} emits. Elsewhere, a new
* {@link GroupedObservable} for this key is created and emits.
*
* A {@link GroupedObservable} represents values belonging to the same group represented by a common key. The common
* key is available as the key field of a {@link GroupedObservable} instance.
*
* The elements emitted by {@link GroupedObservable}s are by default the items emitted by the Observable, or elements
* returned by the elementSelector function.
*
* ## Examples
*
* ### Group objects by id and return as array
*
* ```ts
* import { of } from 'rxjs';
* import { mergeMap, groupBy, reduce } from 'rxjs/operators';
*
* of(
* {id: 1, name: 'JavaScript'},
* {id: 2, name: 'Parcel'},
* {id: 2, name: 'webpack'},
* {id: 1, name: 'TypeScript'},
* {id: 3, name: 'TSLint'}
* ).pipe(
* groupBy(p => p.id),
* mergeMap((group$) => group$.pipe(reduce((acc, cur) => [...acc, cur], []))),
* )
* .subscribe(p => console.log(p));
*
* // displays:
* // [ { id: 1, name: 'JavaScript'},
* // { id: 1, name: 'TypeScript'} ]
* //
* // [ { id: 2, name: 'Parcel'},
* // { id: 2, name: 'webpack'} ]
* //
* // [ { id: 3, name: 'TSLint'} ]
* ```
*
* ### Pivot data on the id field
*
* ```ts
* import { of } from 'rxjs';
* import { groupBy, map, mergeMap, reduce } from 'rxjs/operators';
*
* of(
* { id: 1, name: 'JavaScript' },
* { id: 2, name: 'Parcel' },
* { id: 2, name: 'webpack' },
* { id: 1, name: 'TypeScript' },
* { id: 3, name: 'TSLint' }
* )
* .pipe(
* groupBy(p => p.id, p => p.name),
* mergeMap(group$ =>
* group$.pipe(reduce((acc, cur) => [...acc, cur], [`${group$.key}`]))
* ),
* map(arr => ({ id: parseInt(arr[0], 10), values: arr.slice(1) }))
* )
* .subscribe(p => console.log(p));
*
* // displays:
* // { id: 1, values: [ 'JavaScript', 'TypeScript' ] }
* // { id: 2, values: [ 'Parcel', 'webpack' ] }
* // { id: 3, values: [ 'TSLint' ] }
* ```
*
* @param {function(value: T): K} keySelector A function that extracts the key
* for each item.
* @param {function(value: T): R} [elementSelector] A function that extracts the
* return element for each item.
* @param {function(grouped: GroupedObservable<K,R>): Observable<any>} [durationSelector]
* A function that returns an Observable to determine how long each group should
* exist.
* @return {Observable<GroupedObservable<K,R>>} An Observable that emits
* GroupedObservables, each of which corresponds to a unique key value and each
* of which emits those items from the source Observable that share that key
* value.
* @method groupBy
* @owner Observable
*/
export function groupBy<T, K, R>(keySelector: (value: T) => K,
elementSelector?: ((value: T) => R) | void,
durationSelector?: (grouped: GroupedObservable<K, R>) => Observable<any>,
subjectSelector?: () => Subject<R>): OperatorFunction<T, GroupedObservable<K, R>> {
return (source: Observable<T>) =>
source.lift(new GroupByOperator(keySelector, elementSelector, durationSelector, subjectSelector));
}
export interface RefCountSubscription {
count: number;
unsubscribe: () => void;
closed: boolean;
attemptedToUnsubscribe: boolean;
}
class GroupByOperator<T, K, R> implements Operator<T, GroupedObservable<K, R>> {
constructor(private keySelector: (value: T) => K,
private elementSelector?: ((value: T) => R) | void,
private durationSelector?: (grouped: GroupedObservable<K, R>) => Observable<any>,
private subjectSelector?: () => Subject<R>) {
}
call(subscriber: Subscriber<GroupedObservable<K, R>>, source: any): any {
return source.subscribe(new GroupBySubscriber(
subscriber, this.keySelector, this.elementSelector, this.durationSelector, this.subjectSelector
));
}
}
/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
class GroupBySubscriber<T, K, R> extends Subscriber<T> implements RefCountSubscription {
private groups: Map<K, Subject<T | R>> = null;
public attemptedToUnsubscribe: boolean = false;
public count: number = 0;
constructor(destination: Subscriber<GroupedObservable<K, R>>,
private keySelector: (value: T) => K,
private elementSelector?: ((value: T) => R) | void,
private durationSelector?: (grouped: GroupedObservable<K, R>) => Observable<any>,
private subjectSelector?: () => Subject<R>) {
super(destination);
}
protected _next(value: T): void {
let key: K;
try {
key = this.keySelector(value);
} catch (err) {
this.error(err);
return;
}
this._group(value, key);
}
private _group(value: T, key: K) {
let groups = this.groups;
if (!groups) {
groups = this.groups = new Map<K, Subject<T | R>>();
}
let group = groups.get(key);
let element: R;
if (this.elementSelector) {
try {
element = this.elementSelector(value);
} catch (err) {
this.error(err);
}
} else {
element = <any>value;
}
if (!group) {
group = (this.subjectSelector ? this.subjectSelector() : new Subject<R>()) as Subject<T | R>;
groups.set(key, group);
const groupedObservable = new GroupedObservable(key, group, this);
this.destination.next(groupedObservable);
if (this.durationSelector) {
let duration: any;
try {
duration = this.durationSelector(new GroupedObservable<K, R>(key, <Subject<R>>group));
} catch (err) {
this.error(err);
return;
}
this.add(duration.subscribe(new GroupDurationSubscriber(key, group, this)));
}
}
if (!group.closed) {
group.next(element);
}
}
protected _error(err: any): void {
const groups = this.groups;
if (groups) {
groups.forEach((group, key) => {
group.error(err);
});
groups.clear();
}
this.destination.error(err);
}
protected _complete(): void {
const groups = this.groups;
if (groups) {
groups.forEach((group, key) => {
group.complete();
});
groups.clear();
}
this.destination.complete();
}
removeGroup(key: K): void {
this.groups.delete(key);
}
unsubscribe() {
if (!this.closed) {
this.attemptedToUnsubscribe = true;
if (this.count === 0) {
super.unsubscribe();
}
}
}
}
/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
class GroupDurationSubscriber<K, T> extends Subscriber<T> {
constructor(private key: K,
private group: Subject<T>,
private parent: GroupBySubscriber<any, K, T | any>) {
super(group);
}
protected _next(value: T): void {
this.complete();
}
/** @deprecated This is an internal implementation detail, do not use. */
_unsubscribe() {
const { parent, key } = this;
this.key = this.parent = null;
if (parent) {
parent.removeGroup(key);
}
}
}
/**
* An Observable representing values belonging to the same group represented by
* a common key. The values emitted by a GroupedObservable come from the source
* Observable. The common key is available as the field `key` on a
* GroupedObservable instance.
*
* @class GroupedObservable<K, T>
*/
export class GroupedObservable<K, T> extends Observable<T> {
/** @deprecated Do not construct this type. Internal use only */
constructor(public key: K,
private groupSubject: Subject<T>,
private refCountSubscription?: RefCountSubscription) {
super();
}
/** @deprecated This is an internal implementation detail, do not use. */
_subscribe(subscriber: Subscriber<T>) {
const subscription = new Subscription();
const { refCountSubscription, groupSubject } = this;
if (refCountSubscription && !refCountSubscription.closed) {
subscription.add(new InnerRefCountSubscription(refCountSubscription));
}
subscription.add(groupSubject.subscribe(subscriber));
return subscription;
}
}
/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
class InnerRefCountSubscription extends Subscription {
constructor(private parent: RefCountSubscription) {
super();
parent.count++;
}
unsubscribe() {
const parent = this.parent;
if (!parent.closed && !this.closed) {
super.unsubscribe();
parent.count -= 1;
if (parent.count === 0 && parent.attemptedToUnsubscribe) {
parent.unsubscribe();
}
}
}
}