@typeheim/fire-rx
Advanced tools
Comparing version 0.0.8 to 0.1.0
@@ -9,3 +9,2 @@ export * from './src/Contracts/Observables'; | ||
export * from './src/Observables/ReactiveStream'; | ||
export * from './src/Observables/ReadonlyStream'; | ||
export * from './src/Observables/LazyLoadStream'; | ||
@@ -16,2 +15,1 @@ export * from './src/Observables/StatefulStream'; | ||
export * from './src/Utils/SubscriptionsHub'; | ||
export * from './src/Utils/GarbageCollector'; |
@@ -10,3 +10,3 @@ "use strict"; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -22,3 +22,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./src/Observables/ReactiveStream"), exports); | ||
__exportStar(require("./src/Observables/ReadonlyStream"), exports); | ||
__exportStar(require("./src/Observables/LazyLoadStream"), exports); | ||
@@ -29,3 +28,2 @@ __exportStar(require("./src/Observables/StatefulStream"), exports); | ||
__exportStar(require("./src/Utils/SubscriptionsHub"), exports); | ||
__exportStar(require("./src/Utils/GarbageCollector"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@typeheim/fire-rx", | ||
"version": "0.0.8", | ||
"version": "0.1.0", | ||
"description": "RxJS on steroids", | ||
@@ -30,5 +30,5 @@ "keywords": [ | ||
"devDependencies": { | ||
"rxjs": "^6.6.0" | ||
"rxjs": "^7.2.0" | ||
}, | ||
"gitHead": "50b6dd8a9cf718a7e5b9dd94673a91ffb71c2964" | ||
"gitHead": "a418caeed4e3997928fb7d4fe7e810c47f894346" | ||
} |
@@ -42,3 +42,3 @@ # FireRx | ||
subject.stop() // completes subject and unsubscribe all subscriptions | ||
subject.complete() // completes subject and unsubscribe all subscriptions | ||
``` | ||
@@ -45,0 +45,0 @@ [Read more about all custom observables...](docs/custom-observables.md) |
import { Subscribable } from 'rxjs'; | ||
/** | ||
* @deprecated | ||
*/ | ||
export interface Producer<T> extends Publisher<T> { | ||
} | ||
export interface Publisher<T> extends Subscribable<T> { | ||
@@ -19,7 +14,7 @@ isStopped: boolean; | ||
*/ | ||
stop(): void; | ||
complete(): void; | ||
/** | ||
* Completes producer with error and unsubscribe all subscriptions | ||
*/ | ||
fail(error: any): void; | ||
error(error: any): void; | ||
/** | ||
@@ -46,7 +41,1 @@ * Attaches callbacks for the resolution and/or rejection of the Promise. | ||
} | ||
export interface Observer<T> { | ||
closed?: boolean; | ||
next?: (value: T) => void; | ||
error?: (err: any) => void; | ||
complete?: () => void; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Observer } from '@typeheim/fire-rx'; | ||
import { Observer } from 'rxjs'; | ||
export interface StreamContext<T> { | ||
@@ -3,0 +3,0 @@ next: (value?: T) => void; |
@@ -9,2 +9,4 @@ /** | ||
* By default Angular "ngOnDestroy" destructor is used. | ||
* | ||
* @deprecated please use {@link CompleteOnDestroy} instead | ||
*/ | ||
@@ -11,0 +13,0 @@ export declare function StopOnDestroy(metadata?: DestroyHookMetadata): PropertyDecorator; |
@@ -5,2 +5,6 @@ "use strict"; | ||
/** | ||
* Internal metadata storage for decorators | ||
*/ | ||
const DestructorDecoratorsMetadataMap = new WeakMap(); | ||
/** | ||
* Emit DestroyEvent when destructor specified at metadata param is triggered. | ||
@@ -15,17 +19,3 @@ * By default Angular "ngOnDestroy" destructor is used. | ||
} | ||
return (target, propertyKey) => { | ||
if (!target.hasOwnProperty(metadata.destroyHook)) { | ||
target[metadata.destroyHook] = function () { }; | ||
} | ||
const originalOnDestroy = target[metadata.destroyHook]; | ||
target[metadata.destroyHook] = function (...args) { | ||
try { | ||
this[propertyKey].emit(); | ||
} | ||
catch (error) { | ||
console.log(`@EmitOnDestroy[ERROR]`, error); | ||
} | ||
return originalOnDestroy.apply(this, args); | ||
}; | ||
}; | ||
return attachDestroyHook(metadata, 'emit'); | ||
} | ||
@@ -36,5 +26,7 @@ exports.EmitOnDestroy = EmitOnDestroy; | ||
* By default Angular "ngOnDestroy" destructor is used. | ||
* | ||
* @deprecated please use {@link CompleteOnDestroy} instead | ||
*/ | ||
function StopOnDestroy(metadata) { | ||
return attachDestroyHook(metadata, 'stop'); | ||
return attachDestroyHook(metadata, 'complete'); | ||
} | ||
@@ -66,37 +58,58 @@ exports.StopOnDestroy = StopOnDestroy; | ||
const hookName = config.destroyHook; | ||
const queueProperty = `__fireRxQueue`; | ||
if (!target.hasOwnProperty(queueProperty)) { | ||
target[queueProperty] = {}; | ||
target[queueProperty][config.type] = []; | ||
let destroyQueue; | ||
let decoratorIsWrapped = true; | ||
if (!DestructorDecoratorsMetadataMap.has(target.constructor)) { | ||
DestructorDecoratorsMetadataMap.set(target.constructor, { | ||
stop: [], | ||
complete: [], | ||
unsubscribe: [], | ||
emit: [], | ||
}); | ||
decoratorIsWrapped = false; | ||
} | ||
else if (!target[queueProperty][config.type]) { | ||
target[queueProperty][config.type] = []; | ||
destroyQueue = DestructorDecoratorsMetadataMap.get(target.constructor); | ||
// push property to destroy queue if it wasn't before | ||
if (!destroyQueue[destroyType].includes(propertyKey)) { | ||
destroyQueue[destroyType].push(propertyKey); | ||
} | ||
if (decoratorIsWrapped) { | ||
// prevent wrapping decorator multiple times | ||
return; | ||
} | ||
if (!target.hasOwnProperty(hookName)) { | ||
target[hookName] = function () { }; | ||
Object.defineProperty(target.constructor.prototype, hookName, { | ||
value: function () { }, | ||
configurable: true, | ||
writable: true, | ||
}); | ||
} | ||
target[queueProperty][config.type].push(propertyKey); | ||
// prevent wrapping destructor several times | ||
const patchFlag = `__hookPatchedByFireRx`; | ||
if (target[hookName][patchFlag]) { | ||
return; | ||
} | ||
const originalOnDestroy = target[hookName]; | ||
target[hookName] = function (...args) { | ||
try { | ||
for (let queueType in this[queueProperty]) { | ||
this[queueProperty][queueType].forEach(name => { | ||
this[name][queueType](); | ||
const originalDestructor = target.constructor.prototype[hookName]; | ||
const newDestructorDescriptor = { | ||
value: function (...args) { | ||
var _a; | ||
originalDestructor ? originalDestructor.apply(this, args) : null; | ||
const hooksMetadata = DestructorDecoratorsMetadataMap.get(this.constructor); | ||
for (let destroyType in hooksMetadata) { | ||
(_a = hooksMetadata[destroyType]) === null || _a === void 0 ? void 0 : _a.forEach(property => { | ||
var _a; | ||
try { | ||
if ((_a = this === null || this === void 0 ? void 0 : this[property]) === null || _a === void 0 ? void 0 : _a[destroyType]) { | ||
this[property][destroyType](); | ||
} | ||
} | ||
catch (error) { | ||
let capitalizedType = config.type.charAt(0).toUpperCase() + config.type.slice(1); | ||
console.log(`Error at ${capitalizedType}OnDestroy:`, error); | ||
} | ||
}); | ||
} | ||
} | ||
catch (error) { | ||
let capitalizedType = config.type.charAt(0).toUpperCase() + config.type.slice(1); | ||
console.log(`Error at ${capitalizedType}OnDestroy:`, error); | ||
} | ||
return originalOnDestroy.apply(this, args); | ||
}, | ||
configurable: true, | ||
writeable: true, | ||
}; | ||
target[hookName][patchFlag] = true; | ||
// Deleting old destructor and injecting wrapped one | ||
delete target.constructor.prototype[hookName]; | ||
Object.defineProperty(target.constructor.prototype, hookName, newDestructorDescriptor); | ||
}; | ||
} | ||
//# sourceMappingURL=OnDestroyHooks.js.map |
@@ -18,3 +18,3 @@ "use strict"; | ||
this.internalSubject.next(true); | ||
this.internalSubject.stop(); | ||
this.internalSubject.complete(); | ||
} | ||
@@ -21,0 +21,0 @@ } |
@@ -10,4 +10,4 @@ import { Observable } from 'rxjs'; | ||
*/ | ||
_subscribe(subscriber: any): import("rxjs").TeardownLogic; | ||
protected _subscribe(subscriber: any): any; | ||
protected initDataSource(): void; | ||
} |
@@ -18,2 +18,3 @@ "use strict"; | ||
} | ||
// @ts-ignore | ||
return super._subscribe(subscriber); | ||
@@ -20,0 +21,0 @@ } |
@@ -14,6 +14,2 @@ import { Subscribable, Observable } from 'rxjs'; | ||
/** | ||
* @deprecated will be removed in next release | ||
*/ | ||
emitUntil(destroyEvent: Subscribable<any>): this; | ||
/** | ||
* Attaches callbacks for the resolution and/or rejection of the Promise. | ||
@@ -20,0 +16,0 @@ * @param onfulfilled The callback to execute when the Promise is resolved. |
@@ -43,3 +43,3 @@ "use strict"; | ||
this.internalSubject.next(value); | ||
this.internalSubject.stop(); | ||
this.internalSubject.complete(); | ||
} | ||
@@ -50,3 +50,3 @@ reject(error) { | ||
} | ||
this.internalSubject.fail(error); | ||
this.internalSubject.error(error); | ||
} | ||
@@ -70,13 +70,2 @@ resolveOn(resolveEventOrConfig) { | ||
} | ||
/** | ||
* @deprecated will be removed in next release | ||
*/ | ||
emitUntil(destroyEvent) { | ||
destroyEvent.subscribe(() => { | ||
if (!this.resolved) { | ||
this.internalSubject.stop(); | ||
} | ||
}); | ||
return this; | ||
} | ||
// | ||
@@ -83,0 +72,0 @@ // |
@@ -1,4 +0,3 @@ | ||
import { Observable } from 'rxjs'; | ||
import { Observable, Subscribable } from 'rxjs'; | ||
import { Publisher } from '@typeheim/fire-rx'; | ||
import { Subscribable } from '../Contracts/RxJsInternals'; | ||
import { AsyncStream } from './AsyncStream'; | ||
@@ -17,9 +16,17 @@ export declare class ReactiveStream<T> extends AsyncStream<T> implements Publisher<T> { | ||
/** | ||
* Completes producer and clean up resources | ||
* @deprecated use {@link complete()} instead | ||
*/ | ||
stop(): void; | ||
/** | ||
* Completes producer and clean up resources | ||
*/ | ||
complete(): void; | ||
/** | ||
* @deprecated use {@link error()} instead | ||
*/ | ||
fail(error: any): void; | ||
/** | ||
* Completes producer with error and unsubscribe all subscriptions | ||
*/ | ||
fail(error: any): void; | ||
error(error: any): void; | ||
} |
@@ -28,15 +28,27 @@ "use strict"; | ||
/** | ||
* Completes producer and clean up resources | ||
* @deprecated use {@link complete()} instead | ||
*/ | ||
stop() { | ||
this.sourceSubject.stop(); | ||
this.complete(); | ||
} | ||
/** | ||
* Completes producer with error and unsubscribe all subscriptions | ||
* Completes producer and clean up resources | ||
*/ | ||
complete() { | ||
this.sourceSubject.complete(); | ||
} | ||
/** | ||
* @deprecated use {@link error()} instead | ||
*/ | ||
fail(error) { | ||
this.sourceSubject.fail(error); | ||
this.error(error); | ||
} | ||
/** | ||
* Completes producer with error and unsubscribe all subscriptions | ||
*/ | ||
error(error) { | ||
this.sourceSubject.error(error); | ||
} | ||
} | ||
exports.ReactiveStream = ReactiveStream; | ||
//# sourceMappingURL=ReactiveStream.js.map |
@@ -8,6 +8,1 @@ import { StatefulSubject } from './StatefulSubject'; | ||
} | ||
/** | ||
* @deprecated | ||
*/ | ||
export declare class StatefulProducer<T> extends StatefulStream<T> { | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StatefulProducer = exports.StatefulStream = void 0; | ||
exports.StatefulStream = void 0; | ||
const StatefulSubject_1 = require("./StatefulSubject"); | ||
@@ -11,4 +11,4 @@ const ReactiveStream_1 = require("./ReactiveStream"); | ||
next: (value) => this.sourceSubject.next(value), | ||
stop: () => this.sourceSubject.stop(), | ||
fail: (error) => this.sourceSubject.fail(error), | ||
stop: () => this.sourceSubject.complete(), | ||
fail: (error) => this.sourceSubject.error(error), | ||
isFinished: () => this.isStopped || this.closed, | ||
@@ -22,8 +22,2 @@ isFailed: () => this.sourceSubject.hasError, | ||
exports.StatefulStream = StatefulStream; | ||
/** | ||
* @deprecated | ||
*/ | ||
class StatefulProducer extends StatefulStream { | ||
} | ||
exports.StatefulProducer = StatefulProducer; | ||
//# sourceMappingURL=StatefulStream.js.map |
@@ -1,4 +0,3 @@ | ||
import { SchedulerLike, ReplaySubject, Subscription } from 'rxjs'; | ||
import { SchedulerLike, ReplaySubject, Subscription, Subscribable } from 'rxjs'; | ||
import { Publisher } from '../Contracts/Observables'; | ||
import { Subscribable } from '../Contracts/RxJsInternals'; | ||
import { ReactiveStream } from './ReactiveStream'; | ||
@@ -16,3 +15,3 @@ export declare class StatefulSubject<T> extends ReplaySubject<T> implements Publisher<T> { | ||
*/ | ||
_subscribe(subscriber: any): Subscription; | ||
protected _subscribe(subscriber: any): any; | ||
/** | ||
@@ -28,9 +27,18 @@ * Subscribe to an event to complete and unsubscribe as it | ||
/** | ||
* Completes subject and clean up resources | ||
* @deprecated use {@link complete()} instead | ||
*/ | ||
stop(): void; | ||
/** | ||
* @deprecated use {@link error()} instead | ||
*/ | ||
fail(error: any): void; | ||
/** | ||
* Completes subject and clean up resources | ||
*/ | ||
complete(): void; | ||
/** | ||
* Completes subject with error and unsubscribe all subscriptions | ||
*/ | ||
fail(error: any): void; | ||
error(error: any): void; | ||
protected cleanupResources(): void; | ||
protected get internalPromise(): Promise<T>; | ||
@@ -37,0 +45,0 @@ protected clearInternalPromise(): void; |
@@ -23,2 +23,3 @@ "use strict"; | ||
_subscribe(subscriber) { | ||
//@ts-ignore | ||
let sub = super._subscribe(subscriber); | ||
@@ -33,4 +34,4 @@ this.hub.add(sub); | ||
emitUntil(event) { | ||
event.subscribe(() => { | ||
this.stop(); | ||
event.subscribe({ | ||
next: () => this.complete() | ||
}); | ||
@@ -46,5 +47,17 @@ return this; | ||
/** | ||
* @deprecated use {@link complete()} instead | ||
*/ | ||
stop() { | ||
this.complete(); | ||
} | ||
/** | ||
* @deprecated use {@link error()} instead | ||
*/ | ||
fail(error) { | ||
this.error(error); | ||
} | ||
/** | ||
* Completes subject and clean up resources | ||
*/ | ||
stop() { | ||
complete() { | ||
if (this.hasError) { | ||
@@ -55,6 +68,5 @@ // if subject was failed, further steps ain't necessary | ||
if (!this.isStopped) { | ||
this.complete(); | ||
super.complete(); | ||
} | ||
this.hub.unsubscribe(); | ||
this.clearInternalPromise(); | ||
this.cleanupResources(); | ||
} | ||
@@ -64,6 +76,14 @@ /** | ||
*/ | ||
fail(error) { | ||
this.error(error); | ||
this.hub.unsubscribe(); | ||
error(error) { | ||
if (!this.closed) { | ||
super.error(error); | ||
} | ||
this.cleanupResources(); | ||
} | ||
cleanupResources() { | ||
var _a; | ||
(_a = this === null || this === void 0 ? void 0 : this.hub) === null || _a === void 0 ? void 0 : _a.unsubscribe(); | ||
this.hub = null; // in case if somehow subscriptions will be added | ||
this.clearInternalPromise(); | ||
} | ||
// | ||
@@ -70,0 +90,0 @@ // Promise interface |
@@ -1,2 +0,2 @@ | ||
import { BehaviorSubject, Subscribable, Subscription } from 'rxjs'; | ||
import { BehaviorSubject, Observable, Subscription } from 'rxjs'; | ||
import { Publisher } from '../..'; | ||
@@ -14,3 +14,3 @@ import { ReactiveStream } from './ReactiveStream'; | ||
*/ | ||
_subscribe(subscriber: any): Subscription; | ||
protected _subscribe(subscriber: any): any; | ||
/** | ||
@@ -20,9 +20,21 @@ * Subscribe to an event to complete and unsubscribe as it | ||
*/ | ||
emitUntil(event: Subscribable<any>): this; | ||
emitUntil(event: Observable<any>): this; | ||
/** | ||
* @deprecated use {@link complete()} instead | ||
*/ | ||
stop(): void; | ||
/** | ||
* Completes subject with error and unsubscribe all subscriptions | ||
* @deprecated use {@link error()} instead | ||
*/ | ||
fail(error: any): void; | ||
/** | ||
* Completes subject and clean up resources | ||
*/ | ||
complete(): void; | ||
/** | ||
* Completes subject with error and unsubscribe all subscriptions | ||
*/ | ||
error(error: any): void; | ||
protected cleanupResources(): void; | ||
/** | ||
* Create readonly stream with this subject as source | ||
@@ -29,0 +41,0 @@ */ |
@@ -23,2 +23,3 @@ "use strict"; | ||
_subscribe(subscriber) { | ||
// @ts-ignore | ||
let sub = super._subscribe(subscriber); | ||
@@ -34,7 +35,22 @@ this.hub.add(sub); | ||
event.subscribe(() => { | ||
this.stop(); | ||
this.complete(); | ||
}); | ||
return this; | ||
} | ||
/** | ||
* @deprecated use {@link complete()} instead | ||
*/ | ||
stop() { | ||
this.complete(); | ||
} | ||
/** | ||
* @deprecated use {@link error()} instead | ||
*/ | ||
fail(error) { | ||
this.error(error); | ||
} | ||
/** | ||
* Completes subject and clean up resources | ||
*/ | ||
complete() { | ||
if (this.hasError) { | ||
@@ -45,6 +61,5 @@ // if subject was failed, further steps ain't necessary | ||
if (!this.isStopped) { | ||
this.complete(); | ||
super.complete(); | ||
} | ||
this.hub.unsubscribe(); | ||
this.clearInternalPromise(); | ||
this.cleanupResources(); | ||
} | ||
@@ -54,8 +69,12 @@ /** | ||
*/ | ||
fail(error) { | ||
this.error(error); | ||
this.hub.unsubscribe(); | ||
error(error) { | ||
if (!this.closed) { | ||
this.unsubscribe(); | ||
super.error(error); | ||
} | ||
this.cleanupResources(); | ||
} | ||
cleanupResources() { | ||
var _a; | ||
(_a = this === null || this === void 0 ? void 0 : this.hub) === null || _a === void 0 ? void 0 : _a.unsubscribe(); | ||
this.hub = null; // in case if somehow subscriptions will be added | ||
this.clearInternalPromise(); | ||
@@ -62,0 +81,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import { Unsubscribable, TeardownLogic } from '../Contracts/RxJsInternals'; | ||
import { DestroyEvent } from '../Observables/DestroyEvent'; | ||
import { TeardownLogic, Unsubscribable } from 'rxjs'; | ||
/** | ||
@@ -4,0 +4,0 @@ * @deprecated will be removed in next release |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67158
45
1163