Socket
Socket
Sign inDemoInstall

@effection/subscription

Package Overview
Dependencies
Maintainers
1
Versions
151
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effection/subscription - npm Package Compare versions

Comparing version 0.7.0-7f97ad4 to 0.7.0-b3f13b2

dist/match.d.ts

1

CHANGELOG.md

@@ -8,2 +8,3 @@ # @effection/subscription

- ad0d7e2: add higher order functions like `map`, `filter`, and `forEach` for working with subscriptions
- 3336949: Add the `match` method to `Subscribable` to filter a subscription by pattern

@@ -10,0 +11,0 @@ ## 0.6.3

import { Operation } from 'effection';
import { Subscription, Subscriber } from './subscription';
import { DeepPartial } from './match';
export declare const SymbolSubscribable: unique symbol;

@@ -18,2 +19,3 @@ export interface Subscribable<T, TReturn> {

filter(predicate: (value: T) => boolean): Chain<T, TReturn>;
match(reference: DeepPartial<T>): Chain<T, TReturn>;
chain<X = T, XReturn = TReturn>(next: (source: SubscriptionSource<T, TReturn>) => Subscriber<X, XReturn>): Chain<X, XReturn>;

@@ -20,0 +22,0 @@ forEach(visit: (value: T) => Operation<void>): Operation<TReturn>;

@@ -80,2 +80,18 @@ 'use strict';

function matcher(reference) {
return function (value) {
if (typeof value === 'object' && typeof reference === 'object') {
var castedValue = value;
var castedReference = reference;
return Object.entries(castedReference).every(function (_ref) {
var key = _ref[0],
ref = _ref[1];
return matcher(ref)(castedValue[key]);
});
} else {
return value === reference;
}
};
}
var SymbolSubscribable = /*#__PURE__*/Symbol["for"]('Symbol.subscription');

@@ -134,2 +150,6 @@

_proto.match = function match(reference) {
return this.filter(matcher(reference));
};
_proto.chain = function chain(next) {

@@ -136,0 +156,0 @@ return new Chain(createSubscription(next(this.source)));

2

dist/subscription.cjs.production.min.js

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

"use strict";var n=require("effection"),r=function(){var n=this;this.waiters=[],this.signal=function(r){var t=n.waiters.pop();t&&t(r)},this.wait=function(){return new Promise((function(r){return n.waiters.push(r)}))}};function*t(t){var e=[],i=new r,u=function(n){e.push({done:!1,value:n}),i.signal()};return yield n.resource({next:function(){try{var n=i.wait();return e.length>0&&i.signal(),Promise.resolve(n.then((function(){return e.shift()})))}catch(n){return Promise.reject(n)}}},(function*(){try{var n=yield t((function(n){return u(n)}));e.push({done:!0,value:n}),i.signal()}finally{u=function(n){throw function(n){var r=new Error("tried to publish a value: "+n+" on an already finished subscription");return r.name="TypeError",r}(n)}}}))}var e=Symbol.for("Symbol.subscription");function*i(n,r){for(var t=yield c(n);;){var e=yield t.next();if(e.done)return e.value;yield r(e.value)}}var u={from:function(n){return new o(n)}},o=function(){function n(n){this.source=n}var r=n.prototype;return r[e]=function(){return c(this.source)},r.map=function(n){return this.chain((function(r){return function(t){return i(r,(function*(r){t(n(r))}))}}))},r.filter=function(n){return this.chain((function(r){return function(t){return i(r,(function*(r){n(r)&&t(r)}))}}))},r.chain=function(r){return new n(t(r(this.source)))},r.forEach=function(n){return i(this.source,n)},r.first=function*(){var n=yield c(this.source),r=yield n.next();return r.done?void 0:r.value},n}();function c(n){if(s(n)){var r=s(n);if(r)return r.call(n);var t=new Error("cannot subscribe to "+n+" because it does not contain Symbol.subscription");throw t.name="TypeError",t}return n}function s(n){return n[e]}exports.Subscribable=u,exports.SymbolSubscribable=e,exports.createSubscription=t,exports.forEach=i;
"use strict";var n=require("effection"),r=function(){var n=this;this.waiters=[],this.signal=function(r){var t=n.waiters.pop();t&&t(r)},this.wait=function(){return new Promise((function(r){return n.waiters.push(r)}))}};function*t(t){var e=[],i=new r,u=function(n){e.push({done:!1,value:n}),i.signal()};return yield n.resource({next:function(){try{var n=i.wait();return e.length>0&&i.signal(),Promise.resolve(n.then((function(){return e.shift()})))}catch(n){return Promise.reject(n)}}},(function*(){try{var n=yield t((function(n){return u(n)}));e.push({done:!0,value:n}),i.signal()}finally{u=function(n){throw function(n){var r=new Error("tried to publish a value: "+n+" on an already finished subscription");return r.name="TypeError",r}(n)}}}))}var e=Symbol.for("Symbol.subscription");function*i(n,r){for(var t=yield c(n);;){var e=yield t.next();if(e.done)return e.value;yield r(e.value)}}var u={from:function(n){return new o(n)}},o=function(){function n(n){this.source=n}var r=n.prototype;return r[e]=function(){return c(this.source)},r.map=function(n){return this.chain((function(r){return function(t){return i(r,(function*(r){t(n(r))}))}}))},r.filter=function(n){return this.chain((function(r){return function(t){return i(r,(function*(r){n(r)&&t(r)}))}}))},r.match=function(n){return this.filter(function n(r){return function(t){if("object"==typeof t&&"object"==typeof r){var e=t;return Object.entries(r).every((function(r){var t=r[0];return n(r[1])(e[t])}))}return t===r}}(n))},r.chain=function(r){return new n(t(r(this.source)))},r.forEach=function(n){return i(this.source,n)},r.first=function*(){var n=yield c(this.source),r=yield n.next();return r.done?void 0:r.value},n}();function c(n){if(s(n)){var r=s(n);if(r)return r.call(n);var t=new Error("cannot subscribe to "+n+" because it does not contain Symbol.subscription");throw t.name="TypeError",t}return n}function s(n){return n[e]}exports.Subscribable=u,exports.SymbolSubscribable=e,exports.createSubscription=t,exports.forEach=i;
//# sourceMappingURL=subscription.cjs.production.min.js.map

@@ -78,2 +78,18 @@ import { resource } from 'effection';

function matcher(reference) {
return function (value) {
if (typeof value === 'object' && typeof reference === 'object') {
var castedValue = value;
var castedReference = reference;
return Object.entries(castedReference).every(function (_ref) {
var key = _ref[0],
ref = _ref[1];
return matcher(ref)(castedValue[key]);
});
} else {
return value === reference;
}
};
}
var SymbolSubscribable = /*#__PURE__*/Symbol["for"]('Symbol.subscription');

@@ -132,2 +148,6 @@

_proto.match = function match(reference) {
return this.filter(matcher(reference));
};
_proto.chain = function chain(next) {

@@ -134,0 +154,0 @@ return new Chain(createSubscription(next(this.source)));

{
"name": "@effection/subscription",
"version": "0.7.0-7f97ad4",
"version": "0.7.0-b3f13b2",
"description": "Effection Subscriptions",

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

@@ -91,2 +91,12 @@ # @effection/subscription

### Subscribable#match(reference)
Return a new `Subscribable` that only produces items from its source that match
`reference` in the sense that the produced items have the same properties and
values as `reference`.
``` javascript
Subscribable.from(websocket).match({ type: 'command' });
```
### Subscribable#first()

@@ -93,0 +103,0 @@

import { Operation } from 'effection';
import { Subscription, createSubscription, Subscriber } from './subscription';
import { DeepPartial, matcher } from './match';

@@ -49,2 +50,6 @@ export const SymbolSubscribable: unique symbol = Symbol.for('Symbol.subscription');

match(reference: DeepPartial<T>): Chain<T,TReturn> {
return this.filter(matcher(reference));
}
chain<X = T,XReturn = TReturn>(next: (source: SubscriptionSource<T,TReturn>) => Subscriber<X,XReturn>): Chain<X,XReturn> {

@@ -51,0 +56,0 @@ return new Chain(createSubscription(next(this.source)));

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