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

derive-state

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

derive-state - npm Package Compare versions

Comparing version 0.1.0-alpha.5 to 0.1.0-alpha.6

dist/operators/just.d.ts

36

dist/derive-state.cjs.development.js

@@ -331,2 +331,9 @@ 'use strict';

var just = function just(value) {
return new Stateless(function (obs) {
obs.next(value);
obs.complete();
});
};
var map = function map(mapFn) {

@@ -367,2 +374,29 @@ return function (source) {

var scan = function scan(accumulator, initialValue) {
var hasInitialValue = arguments.length >= 2;
return function (source) {
return new Stateless(function (obs) {
var acc = hasInitialValue ? typeof initialValue === 'function' ? initialValue() : initialValue : EMPTY$2;
if (hasInitialValue) {
obs.next(acc);
}
var index = 0;
return source.subscribe(function (value) {
if (acc === EMPTY$2) {
acc = value;
obs.next(value);
index++;
return;
}
acc = accumulator(acc, value, index);
index++;
}, obs.complete);
});
};
};
var EMPTY$2 = /*#__PURE__*/Symbol('empty');
var skip = function skip(n) {

@@ -477,4 +511,6 @@ return function (source) {

exports.filter = filter;
exports.just = just;
exports.map = map;
exports.merge = merge;
exports.scan = scan;
exports.skip = skip;

@@ -481,0 +517,0 @@ exports.skipSynchronous = skipSynchronous;

2

dist/derive-state.cjs.production.min.js

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

"use strict";function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function e(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}Object.defineProperty(exports,"__esModule",{value:!0});var n=function(){function t(){this.observers=new Set,this.closed=!1}var n=t.prototype;return n.addObserver=function(t){var e=this;if(this.closed)throw new Error("StatelessObservable was closed, can't subscribe");return this.observers.add(t),function(){e.observers.delete(t)}},n.emit=function(t){if(this.closed)throw new Error("Observable was closed, can't emit new value");this.observers.forEach((function(e){return e.next(t)}))},n.close=function(){this.observers.forEach((function(t){return t.complete()})),this.observers.clear(),this.closed=!0},e(t,[{key:"size",get:function(){return this.observers.size}}]),t}(),r=function(){},i=function(){function t(t){var e=this;this.observerList=new n,this.state=o,this.teardown=r,this.pipe=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var i=n[0],o=n.slice(1),s=i(e);return o.forEach((function(t){s=t(s)})),s},arguments.length>=1&&(this.state=t)}var i=t.prototype;return i.setValue=function(t){if(this.observerList.closed)throw new Error("Can't set the value of a closed ObservableState");this.state=t,this.observerList.emit(t)},i.subscribe=function(t,e){var n={next:t,complete:e||r};if(this.observerList.closed)return this.state!==o&&t(this.state),null==e||e(),r;var i=this.observerList.addObserver(n);return this.state!==o&&t(this.state),i},i.appendTeardown=function(t){var e=this.teardown;this.teardown=function(){e(),t()}},i.close=function(){this.teardown(),this.observerList.close()},i.hasValue=function(){return this.state!==o},i.getValue=function(){if(this.state===o)throw new Error("Can't retreive the value of the ObservableState, as it's empty");return this.state},e(t,[{key:"value",get:function(){var t=this;return new Promise((function(e,n){if(t.hasValue())return e(t.getValue());var r=t.subscribe((function(t){r(),e(t)}),(function(){return n(new Error("ObservableState completed without any value"))}))}))}}]),t}(),o=Symbol("empty"),s=function(){function t(t){var e=this;void 0===t&&(t=r),this.observerList=new n,this.teardown=r,this.pipe=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var i=n[0],o=n.slice(1),s=i(e);return o.forEach((function(t){s=t(s)})),s},this.start=t}var e=t.prototype;return e.emit=function(t){this.observerList.emit(t)},e.subscribe=function(t,e){var n=this,i={next:t,complete:e||r};if(this.observerList.closed)return i.complete(),r;var o=this.observerList.addObserver(i);return 1===this.observerList.size&&(this.teardown=this.start({next:function(t){return n.emit(t)},complete:function(){return n.close()}})||r),function(){o(),0===n.observerList.size&&n.teardown()}},e.close=function(){this.teardown(),this.observerList.close()},e.capture=function(){var t=new i,e=this.subscribe((function(e){return t.setValue(e)}),(function(){return t.close()}));return t.appendTeardown(e),t},t}(),u=Symbol("empty");exports.State=i,exports.Stateless=s,exports.asStateless=function(t){return new s((function(e){return t.subscribe(e.next,e.complete)}))},exports.combine=function(t){return new s((function(e){var n=!1,r=Array.isArray(t)?[]:{},i=Object.entries(t);if(0===i.length)return e.complete();var o=i.map((function(t){var o=t[0];return t[1].subscribe((function(t){r[o]=t,(n||Object.keys(r).length===i.length)&&(n=!0,e.next(r))}),e.complete)}));return function(){return o.forEach((function(t){return t()}))}}))},exports.distinctUntilChanged=function(t){return void 0===t&&(t=function(t,e){return t===e}),function(e){return new s((function(n){var r=u;return e.subscribe((function(e){r!==u&&t(e,r)||n.next(e),r=e}),n.complete)}))}},exports.filter=function(t){return function(e){return new s((function(n){return e.subscribe((function(e){return t(e)?n.next(e):void 0}),n.complete)}))}},exports.map=function(t){return function(e){return new s((function(n){return e.subscribe((function(e){return n.next(t(e))}),n.complete)}))}},exports.merge=function(t){return new s((function(e){var n=t.length;if(0===n)return e.complete();var r=t.map((function(t){return t.subscribe(e.next,(function(){0==--n&&e.complete()}))}));return function(){return r.forEach((function(t){return t()}))}}))},exports.skip=function(t){return function(e){return new s((function(n){var r=0;return e.subscribe((function(e){r>=t?n.next(e):r++}),n.complete)}))}},exports.skipSynchronous=function(){return function(t){return new s((function(e){var n={skip:!0},r=t.subscribe((function(t){return n.skip?void 0:e.next(t)}),e.complete);return n.skip=!1,r}))}},exports.switchMap=function(t){return function(e){return new s((function(n){var r=function(){},i=1,o=function(){0==--i&&n.complete()},s=e.subscribe((function(e){r(),i++;var s=t(e);r=s.subscribe((function(t){return n.next(t)}),o)}),o);return function(){r(),s()}}))}},exports.take=function(t){return function(e){return new s((function(n){if(t<1)return n.complete();var r=0,i=e.subscribe((function(e){r<t&&n.next(e),++r>=t&&(i&&i(),n.complete())}),n.complete);return r>=t&&(i(),n.complete()),i}))}},exports.withDefault=function(t){return function(e){return new s((function(n){return n.next(t),e.subscribe(n.next,n.complete)}))}};
"use strict";function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function e(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}Object.defineProperty(exports,"__esModule",{value:!0});var n=function(){function t(){this.observers=new Set,this.closed=!1}var n=t.prototype;return n.addObserver=function(t){var e=this;if(this.closed)throw new Error("StatelessObservable was closed, can't subscribe");return this.observers.add(t),function(){e.observers.delete(t)}},n.emit=function(t){if(this.closed)throw new Error("Observable was closed, can't emit new value");this.observers.forEach((function(e){return e.next(t)}))},n.close=function(){this.observers.forEach((function(t){return t.complete()})),this.observers.clear(),this.closed=!0},e(t,[{key:"size",get:function(){return this.observers.size}}]),t}(),r=function(){},i=function(){function t(t){var e=this;this.observerList=new n,this.state=o,this.teardown=r,this.pipe=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var i=n[0],o=n.slice(1),s=i(e);return o.forEach((function(t){s=t(s)})),s},arguments.length>=1&&(this.state=t)}var i=t.prototype;return i.setValue=function(t){if(this.observerList.closed)throw new Error("Can't set the value of a closed ObservableState");this.state=t,this.observerList.emit(t)},i.subscribe=function(t,e){var n={next:t,complete:e||r};if(this.observerList.closed)return this.state!==o&&t(this.state),null==e||e(),r;var i=this.observerList.addObserver(n);return this.state!==o&&t(this.state),i},i.appendTeardown=function(t){var e=this.teardown;this.teardown=function(){e(),t()}},i.close=function(){this.teardown(),this.observerList.close()},i.hasValue=function(){return this.state!==o},i.getValue=function(){if(this.state===o)throw new Error("Can't retreive the value of the ObservableState, as it's empty");return this.state},e(t,[{key:"value",get:function(){var t=this;return new Promise((function(e,n){if(t.hasValue())return e(t.getValue());var r=t.subscribe((function(t){r(),e(t)}),(function(){return n(new Error("ObservableState completed without any value"))}))}))}}]),t}(),o=Symbol("empty"),s=function(){function t(t){var e=this;void 0===t&&(t=r),this.observerList=new n,this.teardown=r,this.pipe=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var i=n[0],o=n.slice(1),s=i(e);return o.forEach((function(t){s=t(s)})),s},this.start=t}var e=t.prototype;return e.emit=function(t){this.observerList.emit(t)},e.subscribe=function(t,e){var n=this,i={next:t,complete:e||r};if(this.observerList.closed)return i.complete(),r;var o=this.observerList.addObserver(i);return 1===this.observerList.size&&(this.teardown=this.start({next:function(t){return n.emit(t)},complete:function(){return n.close()}})||r),function(){o(),0===n.observerList.size&&n.teardown()}},e.close=function(){this.teardown(),this.observerList.close()},e.capture=function(){var t=new i,e=this.subscribe((function(e){return t.setValue(e)}),(function(){return t.close()}));return t.appendTeardown(e),t},t}(),u=Symbol("empty"),c=Symbol("empty");exports.State=i,exports.Stateless=s,exports.asStateless=function(t){return new s((function(e){return t.subscribe(e.next,e.complete)}))},exports.combine=function(t){return new s((function(e){var n=!1,r=Array.isArray(t)?[]:{},i=Object.entries(t);if(0===i.length)return e.complete();var o=i.map((function(t){var o=t[0];return t[1].subscribe((function(t){r[o]=t,(n||Object.keys(r).length===i.length)&&(n=!0,e.next(r))}),e.complete)}));return function(){return o.forEach((function(t){return t()}))}}))},exports.distinctUntilChanged=function(t){return void 0===t&&(t=function(t,e){return t===e}),function(e){return new s((function(n){var r=u;return e.subscribe((function(e){r!==u&&t(e,r)||n.next(e),r=e}),n.complete)}))}},exports.filter=function(t){return function(e){return new s((function(n){return e.subscribe((function(e){return t(e)?n.next(e):void 0}),n.complete)}))}},exports.just=function(t){return new s((function(e){e.next(t),e.complete()}))},exports.map=function(t){return function(e){return new s((function(n){return e.subscribe((function(e){return n.next(t(e))}),n.complete)}))}},exports.merge=function(t){return new s((function(e){var n=t.length;if(0===n)return e.complete();var r=t.map((function(t){return t.subscribe(e.next,(function(){0==--n&&e.complete()}))}));return function(){return r.forEach((function(t){return t()}))}}))},exports.scan=function(t,e){var n=arguments.length>=2;return function(r){return new s((function(i){var o=n?"function"==typeof e?e():e:c;n&&i.next(o);var s=0;return r.subscribe((function(e){if(o===c)return o=e,i.next(e),void s++;o=t(o,e,s),s++}),i.complete)}))}},exports.skip=function(t){return function(e){return new s((function(n){var r=0;return e.subscribe((function(e){r>=t?n.next(e):r++}),n.complete)}))}},exports.skipSynchronous=function(){return function(t){return new s((function(e){var n={skip:!0},r=t.subscribe((function(t){return n.skip?void 0:e.next(t)}),e.complete);return n.skip=!1,r}))}},exports.switchMap=function(t){return function(e){return new s((function(n){var r=function(){},i=1,o=function(){0==--i&&n.complete()},s=e.subscribe((function(e){r(),i++;var s=t(e);r=s.subscribe((function(t){return n.next(t)}),o)}),o);return function(){r(),s()}}))}},exports.take=function(t){return function(e){return new s((function(n){if(t<1)return n.complete();var r=0,i=e.subscribe((function(e){r<t&&n.next(e),++r>=t&&(i&&i(),n.complete())}),n.complete);return r>=t&&(i(),n.complete()),i}))}},exports.withDefault=function(t){return function(e){return new s((function(n){return n.next(t),e.subscribe(n.next,n.complete)}))}};
//# sourceMappingURL=derive-state.cjs.production.min.js.map

@@ -327,2 +327,9 @@ function _defineProperties(target, props) {

var just = function just(value) {
return new Stateless(function (obs) {
obs.next(value);
obs.complete();
});
};
var map = function map(mapFn) {

@@ -363,2 +370,29 @@ return function (source) {

var scan = function scan(accumulator, initialValue) {
var hasInitialValue = arguments.length >= 2;
return function (source) {
return new Stateless(function (obs) {
var acc = hasInitialValue ? typeof initialValue === 'function' ? initialValue() : initialValue : EMPTY$2;
if (hasInitialValue) {
obs.next(acc);
}
var index = 0;
return source.subscribe(function (value) {
if (acc === EMPTY$2) {
acc = value;
obs.next(value);
index++;
return;
}
acc = accumulator(acc, value, index);
index++;
}, obs.complete);
});
};
};
var EMPTY$2 = /*#__PURE__*/Symbol('empty');
var skip = function skip(n) {

@@ -467,3 +501,3 @@ return function (source) {

export { State, Stateless, asStateless, combine, distinctUntilChanged, filter, map, merge, skip, skipSynchronous, switchMap, take, withDefault };
export { State, Stateless, asStateless, combine, distinctUntilChanged, filter, just, map, merge, scan, skip, skipSynchronous, switchMap, take, withDefault };
//# sourceMappingURL=derive-state.esm.js.map
export * from './combine';
export * from './distinctUntilChanged';
export * from './filter';
export * from './just';
export * from './map';
export * from './merge';
export * from './scan';
export * from './skip';

@@ -7,0 +9,0 @@ export * from './skipSynchronous';

{
"version": "0.1.0-alpha.5",
"version": "0.1.0-alpha.6",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

@@ -177,2 +177,3 @@ # DeriveState

- `just(value)`: Emits `value` on the first subscription.
- `combine(obj)`: subscribes to every observable in `obj`, and emits the value of all of them in the same structure as `obj` (works with arrays too)

@@ -188,2 +189,4 @@ - `merge(array)`: subscribes to all the observables in array and emits every value from them.

- `take(n)`: updates at most N times.
- `skip(n)`: skips the first N values.
- `withDefault(value)`: adds in a value if none is present.
- `scan(accumulator, initialValue?)`: accumulates and emits values using the accumulator function
export * from './combine';
export * from './distinctUntilChanged';
export * from './filter';
export * from './just';
export * from './map';
export * from './merge';
export * from './scan';
export * from './skip';

@@ -7,0 +9,0 @@ export * from './skipSynchronous';

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