Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@reactive-js/observable

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reactive-js/observable - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

37

dist/cjs/internal/fromArray.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const rx_1 = require("@reactive-js/rx");
exports.fromArray = (values, delay = 0) => {
const subscribe = (subscriber) => {
let index = 0;
let startIndex = 0;
const continuation = shouldYield => {
while (index < values.length && !subscriber.isDisposed) {
const value = values[index];
index++;
subscriber.next(value);
if (shouldYield() || delay > 0) {
return continuationResult;
try {
const length = values.length;
let index = startIndex;
while (index < length && !subscriber.isDisposed) {
const value = values[index];
index++;
subscriber.nextUnsafe(value);
if (shouldYield() || delay > 0) {
startIndex = index;
return continuationResult;
}
}
subscriber.complete();
return;
}
subscriber.complete();
return;
catch (cause) {
subscriber.complete({ cause });
return;
}
};

@@ -22,3 +32,10 @@ const continuationResult = {

};
subscriber.schedule(continuation, delay);
if (subscriber instanceof rx_1.AbstractDelegatingSubscriber) {
subscriber.schedule(continuation, delay);
}
else {
subscriber.schedule(() => {
subscriber.complete();
}, delay);
}
};

@@ -25,0 +42,0 @@ return { subscribe };

@@ -32,3 +32,2 @@ "use strict";

}
;
get result() {

@@ -35,0 +34,0 @@ if (this.error !== undefined) {

@@ -16,3 +16,4 @@ "use strict";

this.observer.next(data);
if (this.delegate.nextUnsafe !== undefined) {
if (this.delegate.nextUnsafe !==
undefined) {
this.delegate.nextUnsafe(data);

@@ -19,0 +20,0 @@ }

@@ -26,23 +26,37 @@ "use strict";

};
class ToPromiseObserver {
constructor(subscription, resolve, reject) {
this.result = undefined;
this.subscription = subscription;
this.resolve = resolve;
this.reject = reject;
}
next(x) {
if (this.result === undefined) {
this.result = [x];
}
else {
this.result[0] = x;
}
}
complete(err) {
this.subscription.dispose();
if (err !== undefined) {
const { cause } = err;
this.reject(cause);
}
else if (this.result === undefined) {
this.reject(new Error("Observable completed without producing a value"));
}
else {
const value = this.result[0];
this.resolve(value);
}
}
}
exports.toPromise = (scheduler) => observable => new Promise((resolve, reject) => {
let result = undefined;
const subscription = pipe_1.pipe(observable, observe_1.observe({
next: v => {
result = v;
},
complete: err => {
subscription.dispose();
if (err !== undefined) {
const { cause } = err;
reject(cause);
}
else if (result === undefined) {
reject(new Error("Observable completed without producing a value"));
}
else {
resolve(result);
}
},
}), rx_1.subscribe(scheduler));
const subscription = disposable_1.createSerialDisposable();
const observer = new ToPromiseObserver(subscription, resolve, reject);
subscription.disposable = pipe_1.pipe(observable, observe_1.observe(observer), rx_1.subscribe(scheduler));
});
//# sourceMappingURL=promise.js.map

@@ -19,3 +19,2 @@ "use strict";

nextUnsafe(data) {
this.innerSubscription.disposable = disposable_1.disposed;
this.innerSubscription.disposable = pipe_1.pipe(data, observe_1.observe(new SwitchSubscriber.InnerObserver(this)), rx_1.subscribe(this));

@@ -22,0 +21,0 @@ }

@@ -22,3 +22,3 @@ "use strict";

const result = this.selector(data, otherLatest);
this.delegate.next(result);
this.delegate.nextUnsafe(result);
}

@@ -45,4 +45,6 @@ }

};
const operator = (other, selector) => subscriber => new WithLatestFromSubscriber(subscriber, other, selector);
const operator = (other, selector) => subscriber => subscriber instanceof rx_1.AbstractDelegatingSubscriber
? new WithLatestFromSubscriber(subscriber, other, selector)
: subscriber;
exports.withLatestFrom = (other, selector) => lift_1.lift(operator(other, selector));
//# sourceMappingURL=withLatestFrom.js.map

@@ -0,15 +1,25 @@

import { AbstractDelegatingSubscriber } from "@reactive-js/rx";
export const fromArray = (values, delay = 0) => {
const subscribe = (subscriber) => {
let index = 0;
let startIndex = 0;
const continuation = shouldYield => {
while (index < values.length && !subscriber.isDisposed) {
const value = values[index];
index++;
subscriber.next(value);
if (shouldYield() || delay > 0) {
return continuationResult;
try {
const length = values.length;
let index = startIndex;
while (index < length && !subscriber.isDisposed) {
const value = values[index];
index++;
subscriber.nextUnsafe(value);
if (shouldYield() || delay > 0) {
startIndex = index;
return continuationResult;
}
}
subscriber.complete();
return;
}
subscriber.complete();
return;
catch (cause) {
subscriber.complete({ cause });
return;
}
};

@@ -20,3 +30,10 @@ const continuationResult = {

};
subscriber.schedule(continuation, delay);
if (subscriber instanceof AbstractDelegatingSubscriber) {
subscriber.schedule(continuation, delay);
}
else {
subscriber.schedule(() => {
subscriber.complete();
}, delay);
}
};

@@ -23,0 +40,0 @@ return { subscribe };

@@ -1,2 +0,2 @@

import { AbstractDelegatingSubscriber } from "@reactive-js/rx";
import { AbstractDelegatingSubscriber, } from "@reactive-js/rx";
import { lift } from "./lift";

@@ -3,0 +3,0 @@ class IgnoreElementsSubscriber extends AbstractDelegatingSubscriber {

@@ -30,3 +30,2 @@ import { subscribe, } from "@reactive-js/rx";

}
;
get result() {

@@ -33,0 +32,0 @@ if (this.error !== undefined) {

@@ -14,3 +14,4 @@ import { AbstractDelegatingSubscriber, } from "@reactive-js/rx";

this.observer.next(data);
if (this.delegate.nextUnsafe !== undefined) {
if (this.delegate.nextUnsafe !==
undefined) {
this.delegate.nextUnsafe(data);

@@ -17,0 +18,0 @@ }

import { subscribe, createObservable, } from "@reactive-js/rx";
import { observe } from "./observe";
import { pipe } from "@reactive-js/pipe";
import { createDisposable } from "@reactive-js/disposable";
import { createDisposable, createSerialDisposable, } from "@reactive-js/disposable";
export const fromPromiseFactory = (factory) => {

@@ -24,23 +24,37 @@ const onSubscribe = (observer) => {

};
class ToPromiseObserver {
constructor(subscription, resolve, reject) {
this.result = undefined;
this.subscription = subscription;
this.resolve = resolve;
this.reject = reject;
}
next(x) {
if (this.result === undefined) {
this.result = [x];
}
else {
this.result[0] = x;
}
}
complete(err) {
this.subscription.dispose();
if (err !== undefined) {
const { cause } = err;
this.reject(cause);
}
else if (this.result === undefined) {
this.reject(new Error("Observable completed without producing a value"));
}
else {
const value = this.result[0];
this.resolve(value);
}
}
}
export const toPromise = (scheduler) => observable => new Promise((resolve, reject) => {
let result = undefined;
const subscription = pipe(observable, observe({
next: v => {
result = v;
},
complete: err => {
subscription.dispose();
if (err !== undefined) {
const { cause } = err;
reject(cause);
}
else if (result === undefined) {
reject(new Error("Observable completed without producing a value"));
}
else {
resolve(result);
}
},
}), subscribe(scheduler));
const subscription = createSerialDisposable();
const observer = new ToPromiseObserver(subscription, resolve, reject);
subscription.disposable = pipe(observable, observe(observer), subscribe(scheduler));
});
//# sourceMappingURL=promise.js.map

@@ -1,2 +0,2 @@

import { createSerialDisposable, disposed } from "@reactive-js/disposable";
import { createSerialDisposable } from "@reactive-js/disposable";
import { subscribe, AbstractDelegatingSubscriber, } from "@reactive-js/rx";

@@ -17,3 +17,2 @@ import { lift } from "./lift";

nextUnsafe(data) {
this.innerSubscription.disposable = disposed;
this.innerSubscription.disposable = pipe(data, observe(new SwitchSubscriber.InnerObserver(this)), subscribe(this));

@@ -20,0 +19,0 @@ }

@@ -20,3 +20,3 @@ import { subscribe, AbstractDelegatingSubscriber, } from "@reactive-js/rx";

const result = this.selector(data, otherLatest);
this.delegate.next(result);
this.delegate.nextUnsafe(result);
}

@@ -43,4 +43,6 @@ }

};
const operator = (other, selector) => subscriber => new WithLatestFromSubscriber(subscriber, other, selector);
const operator = (other, selector) => subscriber => subscriber instanceof AbstractDelegatingSubscriber
? new WithLatestFromSubscriber(subscriber, other, selector)
: subscriber;
export const withLatestFrom = (other, selector) => lift(operator(other, selector));
//# sourceMappingURL=withLatestFrom.js.map
{
"name": "@reactive-js/observable",
"version": "0.0.12",
"version": "0.0.13",
"main": "dist/cjs/index.js",

@@ -41,7 +41,7 @@ "module": "dist/esm5/index.js",

"dependencies": {
"@reactive-js/disposable": "^0.0.12",
"@reactive-js/pipe": "^0.0.12",
"@reactive-js/rx": "^0.0.12",
"@reactive-js/scheduler": "^0.0.12",
"@reactive-js/schedulers": "^0.0.12"
"@reactive-js/disposable": "^0.0.13",
"@reactive-js/pipe": "^0.0.13",
"@reactive-js/rx": "^0.0.13",
"@reactive-js/scheduler": "^0.0.13",
"@reactive-js/schedulers": "^0.0.13"
},

@@ -73,3 +73,3 @@ "devDependencies": {

},
"gitHead": "66ee9bfeeb79e01c9770dc09829bedf292674ff0"
"gitHead": "86211c5e64b3702b5e3b00dc31d40a79f35bd02f"
}

@@ -9,3 +9,6 @@ import {

class DistinctUntilChangedSubscriber<T> extends AbstractDelegatingSubscriber<T, T> {
class DistinctUntilChangedSubscriber<T> extends AbstractDelegatingSubscriber<
T,
T
> {
private equals: (a: T, b: T) => boolean;

@@ -34,3 +37,5 @@ private prev: [T] | undefined;

// sink notifcations to the delegate.
(this.delegate as AbstractDelegatingSubscriber<T, unknown>).nextUnsafe(data);
(this.delegate as AbstractDelegatingSubscriber<T, unknown>).nextUnsafe(
data,
);
}

@@ -37,0 +42,0 @@ }

@@ -1,2 +0,2 @@

import { ObservableLike, SubscriberLike } from "@reactive-js/rx";
import { ObservableLike, SubscriberLike, AbstractDelegatingSubscriber } from "@reactive-js/rx";
import {

@@ -12,17 +12,29 @@ SchedulerContinuationLike,

const subscribe = (subscriber: SubscriberLike<T>) => {
let index = 0;
let startIndex = 0;
const continuation: SchedulerContinuationLike = shouldYield => {
while (index < values.length && !subscriber.isDisposed) {
const value = values[index];
index++;
subscriber.next(value);
try {
const length = values.length;
if (shouldYield() || delay > 0) {
return continuationResult;
let index = startIndex;
while (index < length && !subscriber.isDisposed) {
const value = values[index];
index++;
// Performance: Bypass safety checks and directly
// sink notifications to the delegate.
(subscriber as AbstractDelegatingSubscriber<T, unknown>).nextUnsafe(value);
if (shouldYield() || delay > 0) {
startIndex = index;
return continuationResult;
}
}
subscriber.complete();
return;
} catch (cause) {
subscriber.complete({ cause });
return;
}
subscriber.complete();
return;
};

@@ -34,3 +46,9 @@ const continuationResult: SchedulerContinuationResultLike = {

subscriber.schedule(continuation, delay);
if (subscriber instanceof AbstractDelegatingSubscriber) {
subscriber.schedule(continuation, delay);
} else {
subscriber.schedule(() => {
subscriber.complete();
}, delay);
}
};

@@ -37,0 +55,0 @@

import {
ErrorLike,
SubscriberLike,
AbstractDelegatingSubscriber} from "@reactive-js/rx";
AbstractDelegatingSubscriber,
} from "@reactive-js/rx";
import { ObservableOperatorLike } from "./interfaces";
import { lift } from "./lift";
class IgnoreElementsSubscriber<TA, TB> extends AbstractDelegatingSubscriber<TA, TB> {
class IgnoreElementsSubscriber<TA, TB> extends AbstractDelegatingSubscriber<
TA,
TB
> {
constructor(delegate: SubscriberLike<TB>) {

@@ -24,4 +28,4 @@ super(delegate);

: subscriber;
export const ignoreElements = <TA, TB>(): ObservableOperatorLike<TA, TB> =>
lift(operator);

@@ -21,6 +21,3 @@ import {

const subscription = pipe(
observable,
subscribe(scheduler),
);
const subscription = pipe(observable, subscribe(scheduler));
scheduler.run();

@@ -45,3 +42,3 @@ scheduler.dispose();

this.error = x;
};
}

@@ -53,3 +50,3 @@ get result(): T {

}
if (this._result === undefined) {

@@ -56,0 +53,0 @@ throw new Error("Observable did not produce any values");

@@ -23,6 +23,7 @@ import {

if (shouldKeep) {
// Performance: Bypass safety checks and directly
// sink notifcations to the delegate.
(this.delegate as AbstractDelegatingSubscriber<T, unknown>).nextUnsafe(data);
(this.delegate as AbstractDelegatingSubscriber<T, unknown>).nextUnsafe(
data,
);
}

@@ -29,0 +30,0 @@ }

@@ -25,3 +25,5 @@ import {

// sink notifcations to the delegate.
(this.delegate as AbstractDelegatingSubscriber<TB, unknown>).nextUnsafe(mappedData);
(this.delegate as AbstractDelegatingSubscriber<TB, unknown>).nextUnsafe(
mappedData,
);
}

@@ -28,0 +30,0 @@ }

@@ -13,3 +13,6 @@ import {

class MergeSubscriber<T> extends AbstractDelegatingSubscriber<ObservableLike<T>, T> {
class MergeSubscriber<T> extends AbstractDelegatingSubscriber<
ObservableLike<T>,
T
> {
private activeCount = 0;

@@ -16,0 +19,0 @@ private isCompleted = false;

@@ -25,6 +25,11 @@ import {

// Performance: Only sink notifications if there is
// Performance: Only sink notifications if there is
// another delegate in the subscriber chain.
if ((this.delegate as AbstractDelegatingSubscriber<T, unknown>).nextUnsafe !== undefined) {
(this.delegate as AbstractDelegatingSubscriber<T, unknown>).nextUnsafe(data);
if (
(this.delegate as AbstractDelegatingSubscriber<T, unknown>).nextUnsafe !==
undefined
) {
(this.delegate as AbstractDelegatingSubscriber<T, unknown>).nextUnsafe(
data,
);
}

@@ -31,0 +36,0 @@ }

@@ -6,2 +6,3 @@ import {

createObservable,
ErrorLike,
} from "@reactive-js/rx";

@@ -11,3 +12,7 @@ import { SchedulerLike } from "@reactive-js/scheduler";

import { pipe, OperatorLike } from "@reactive-js/pipe";
import { createDisposable } from "@reactive-js/disposable";
import {
createDisposable,
DisposableLike,
createSerialDisposable,
} from "@reactive-js/disposable";

@@ -42,2 +47,41 @@ export const fromPromiseFactory = <T>(

class ToPromiseObserver<T> implements ObserverLike<T> {
private result: [T] | undefined = undefined;
private readonly subscription: DisposableLike;
private readonly resolve: (value?: T | PromiseLike<T>) => void;
private readonly reject: (reason?: any) => void;
constructor(
subscription: DisposableLike,
resolve: (value?: T | PromiseLike<T>) => void,
reject: (reason?: any) => void,
) {
this.subscription = subscription;
this.resolve = resolve;
this.reject = reject;
}
next(x: T) {
if (this.result === undefined) {
this.result = [x];
} else {
this.result[0] = x;
}
}
complete(err?: ErrorLike) {
this.subscription.dispose();
if (err !== undefined) {
const { cause } = err;
this.reject(cause);
} else if (this.result === undefined) {
this.reject(new Error("Observable completed without producing a value"));
} else {
const value = this.result[0];
this.resolve(value);
}
}
}
export const toPromise = <T>(

@@ -47,23 +91,10 @@ scheduler: SchedulerLike,

new Promise((resolve, reject) => {
let result: T | undefined = undefined;
const subscription = pipe(
const subscription = createSerialDisposable();
const observer = new ToPromiseObserver(subscription, resolve, reject);
subscription.disposable = pipe(
observable,
observe({
next: v => {
result = v;
},
complete: err => {
subscription.dispose();
if (err !== undefined) {
const { cause } = err;
reject(cause);
} else if (result === undefined) {
reject(new Error("Observable completed without producing a value"));
} else {
resolve(result);
}
},
}),
observe(observer),
subscribe(scheduler),
);
});

@@ -33,3 +33,5 @@ import {

// sink notifcations to the delegate.
(this.delegate as AbstractDelegatingSubscriber<TAcc, unknown>).nextUnsafe(nextAcc);
(this.delegate as AbstractDelegatingSubscriber<TAcc, unknown>).nextUnsafe(
nextAcc,
);
}

@@ -44,4 +46,4 @@ }

? new ScanSubscriber(subscriber, scanner, initialValue())
: subscriber as SubscriberLike<any>;
: (subscriber as SubscriberLike<any>);
export const scan = <T, TAcc>(

@@ -48,0 +50,0 @@ scanner: (acc: TAcc, next: T) => TAcc,

@@ -1,2 +0,2 @@

import { createSerialDisposable, disposed } from "@reactive-js/disposable";
import { createSerialDisposable } from "@reactive-js/disposable";
import {

@@ -15,3 +15,6 @@ subscribe,

class SwitchSubscriber<T> extends AbstractDelegatingSubscriber<ObservableLike<T>, T> {
class SwitchSubscriber<T> extends AbstractDelegatingSubscriber<
ObservableLike<T>,
T
> {
static InnerObserver = class<T> implements ObserverLike<T> {

@@ -45,3 +48,2 @@ private readonly parent: SwitchSubscriber<T>;

nextUnsafe(data: ObservableLike<T>) {
this.innerSubscription.disposable = disposed;
this.innerSubscription.disposable = pipe(

@@ -48,0 +50,0 @@ data,

@@ -70,3 +70,7 @@ import { DisposableLike } from "@reactive-js/disposable";

const result = this.selector(data, otherLatest);
this.delegate.next(result);
// Performance: Bypass safety checks and directly
// sink notifcations to the delegate.
(this.delegate as AbstractDelegatingSubscriber<TC, unknown>).nextUnsafe(
result,
);
}

@@ -80,3 +84,5 @@ }

): SubscriberOperatorLike<TA, TC> => subscriber =>
new WithLatestFromSubscriber(subscriber, other, selector);
subscriber instanceof AbstractDelegatingSubscriber
? new WithLatestFromSubscriber(subscriber, other, selector)
: (subscriber as SubscriberLike<any>);

@@ -83,0 +89,0 @@ export const withLatestFrom = <TA, TB, TC>(

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

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

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc