subscribable-things 2.0.0 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/build/es2019/factories/wrap-subscribe-function.d.ts.map +1 -1
- package/build/es2019/factories/wrap-subscribe-function.js +5 -2
- package/build/es2019/factories/wrap-subscribe-function.js.map +1 -1
- package/build/es2019/types/observer-parameters.d.ts +2 -2
- package/build/es2019/types/observer-parameters.d.ts.map +1 -1
- package/build/es5/bundle.js +13 -3
- package/package.json +26 -19
- package/src/factories/wrap-subscribe-function.ts +6 -2
- package/src/types/observer-parameters.ts +2 -3
package/README.md
CHANGED
|
@@ -111,6 +111,17 @@ for await (const isMatching of eachValueFrom(source$)) {
|
|
|
111
111
|
}
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
+
Also it's possible to output values directly to HTML via [spect/h.js](https://github.com/spectjs/spect) ([codepen](https://codepen.io/dyv/pen/xxLPRPK)).
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
import { h } from 'spect';
|
|
118
|
+
import { mediaQueryMatch } from 'subscribable-things';
|
|
119
|
+
|
|
120
|
+
const element = h`<div>is matching: ${mediaQueryMatch('(max-width:600px)')}</div>`;
|
|
121
|
+
|
|
122
|
+
document.body.appendChild(element);
|
|
123
|
+
```
|
|
124
|
+
|
|
114
125
|
### animationFrame(): SubscribableThing\<number>
|
|
115
126
|
|
|
116
127
|
This function wraps the [`requestAnimationFrame()`](https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-animationframeprovider-requestanimationframe) method. It emits the current timestamp of each animation frame.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap-subscribe-function.d.ts","sourceRoot":"","sources":["../../../src/factories/wrap-subscribe-function.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wrap-subscribe-function.d.ts","sourceRoot":"","sources":["../../../src/factories/wrap-subscribe-function.ts"],"names":[],"mappings":"AACA,OAAO,EAA+D,6BAA6B,EAAE,MAAM,UAAU,CAAC;AAEtH,eAAO,MAAM,2BAA2B,EAAE,6BAqBzC,CAAC"}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export const createWrapSubscribeFunction = (patch, toObserver) => {
|
|
2
2
|
const emptyFunction = () => { }; // tslint:disable-line:no-empty
|
|
3
|
+
const isNextFunction = (args) => typeof args[0] === 'function';
|
|
3
4
|
return (innerSubscribe) => {
|
|
4
5
|
const subscribe = ((...args) => {
|
|
5
|
-
const unsubscribe = innerSubscribe(toObserver(...args));
|
|
6
|
+
const unsubscribe = innerSubscribe(isNextFunction(args) ? toObserver({ next: args[0] }) : toObserver(...args));
|
|
6
7
|
if (unsubscribe !== undefined) {
|
|
7
8
|
return unsubscribe;
|
|
8
9
|
}
|
|
9
10
|
return emptyFunction;
|
|
10
11
|
});
|
|
11
|
-
subscribe[Symbol.observable] = () => ({
|
|
12
|
+
subscribe[Symbol.observable] = () => ({
|
|
13
|
+
subscribe: (...args) => ({ unsubscribe: subscribe(...args) })
|
|
14
|
+
});
|
|
12
15
|
return patch(subscribe);
|
|
13
16
|
};
|
|
14
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap-subscribe-function.js","sourceRoot":"","sources":["../../../src/factories/wrap-subscribe-function.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wrap-subscribe-function.js","sourceRoot":"","sources":["../../../src/factories/wrap-subscribe-function.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,2BAA2B,GAAkC,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;IAC5F,MAAM,aAAa,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,+BAA+B;IAC/D,MAAM,cAAc,GAAG,CAAI,IAA4B,EAAiC,EAAE,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC;IAEzH,OAAO,CAAI,cAAqC,EAAE,EAAE;QAChD,MAAM,SAAS,GAA0B,CAAC,CAAC,GAAG,IAA4B,EAAE,EAAE;YAC1E,MAAM,WAAW,GAAG,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;YAE/G,IAAI,WAAW,KAAK,SAAS,EAAE;gBAC3B,OAAO,WAAW,CAAC;aACtB;YAED,OAAO,aAAa,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;YAClC,SAAS,EAAE,CAAC,GAAG,IAA8C,EAAE,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;SAC1G,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare type TObserverParameters<T> = Parameters<Subscribable<T>['subscribe']> | [
|
|
1
|
+
import { Observer, Subscribable } from 'rxjs-interop';
|
|
2
|
+
export declare type TObserverParameters<T> = Parameters<Subscribable<T>['subscribe']> | [Observer<T>['next']];
|
|
3
3
|
//# sourceMappingURL=observer-parameters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observer-parameters.d.ts","sourceRoot":"","sources":["../../../src/types/observer-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"observer-parameters.d.ts","sourceRoot":"","sources":["../../../src/types/observer-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEtD,oBAAY,mBAAmB,CAAC,CAAC,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC"}
|
package/build/es5/bundle.js
CHANGED
|
@@ -407,9 +407,9 @@
|
|
|
407
407
|
};
|
|
408
408
|
};
|
|
409
409
|
|
|
410
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
410
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
411
411
|
|
|
412
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
412
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
413
413
|
|
|
414
414
|
var createVideoFrame = function createVideoFrame(emitNotSupportedError, wrapSubscribeFunction) {
|
|
415
415
|
return function (videoElement) {
|
|
@@ -500,9 +500,19 @@
|
|
|
500
500
|
var emptyFunction = function emptyFunction() {}; // tslint:disable-line:no-empty
|
|
501
501
|
|
|
502
502
|
|
|
503
|
+
var isNextFunction = function isNextFunction(args) {
|
|
504
|
+
return typeof args[0] === 'function';
|
|
505
|
+
};
|
|
506
|
+
|
|
503
507
|
return function (innerSubscribe) {
|
|
504
508
|
var _subscribe = function subscribe() {
|
|
505
|
-
var
|
|
509
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
510
|
+
args[_key] = arguments[_key];
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
var unsubscribe = innerSubscribe(isNextFunction(args) ? toObserver({
|
|
514
|
+
next: args[0]
|
|
515
|
+
}) : toObserver.apply(void 0, args));
|
|
506
516
|
|
|
507
517
|
if (unsubscribe !== undefined) {
|
|
508
518
|
return unsubscribe;
|
package/package.json
CHANGED
|
@@ -8,37 +8,43 @@
|
|
|
8
8
|
"path": "cz-conventional-changelog"
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
|
+
"contributors": [
|
|
12
|
+
{
|
|
13
|
+
"email": "df.creative@gmail.com",
|
|
14
|
+
"name": "Dmitry Iv"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
11
17
|
"dependencies": {
|
|
12
|
-
"@babel/runtime": "^7.16.
|
|
18
|
+
"@babel/runtime": "^7.16.5",
|
|
13
19
|
"rxjs-interop": "^2.0.0",
|
|
14
20
|
"tslib": "^2.3.1"
|
|
15
21
|
},
|
|
16
22
|
"description": "A collection of reactive wrappers for various browser APIs.",
|
|
17
23
|
"devDependencies": {
|
|
18
|
-
"@babel/core": "^7.16.
|
|
19
|
-
"@babel/plugin-external-helpers": "^7.16.
|
|
20
|
-
"@babel/plugin-transform-runtime": "^7.16.
|
|
21
|
-
"@babel/preset-env": "^7.16.
|
|
22
|
-
"@commitlint/cli": "^
|
|
23
|
-
"@commitlint/config-angular": "^
|
|
24
|
+
"@babel/core": "^7.16.5",
|
|
25
|
+
"@babel/plugin-external-helpers": "^7.16.5",
|
|
26
|
+
"@babel/plugin-transform-runtime": "^7.16.5",
|
|
27
|
+
"@babel/preset-env": "^7.16.5",
|
|
28
|
+
"@commitlint/cli": "^15.0.0",
|
|
29
|
+
"@commitlint/config-angular": "^15.0.0",
|
|
24
30
|
"@rollup/plugin-babel": "^5.3.0",
|
|
25
31
|
"baconjs": "^3.0.17",
|
|
26
|
-
"body-parser": "^1.19.
|
|
32
|
+
"body-parser": "^1.19.1",
|
|
27
33
|
"callbag-basics": "^4.0.0",
|
|
28
34
|
"chai": "^4.3.4",
|
|
29
35
|
"commitizen": "^4.2.4",
|
|
30
36
|
"cz-conventional-changelog": "^3.3.0",
|
|
31
37
|
"eslint": "^7.32.0",
|
|
32
|
-
"eslint-config-holy-grail": "^50.1.
|
|
38
|
+
"eslint-config-holy-grail": "^50.1.22",
|
|
33
39
|
"grunt": "^1.4.1",
|
|
34
40
|
"grunt-cli": "^1.4.3",
|
|
35
41
|
"grunt-contrib-clean": "^2.0.0",
|
|
36
42
|
"grunt-sh": "^0.2.0",
|
|
37
43
|
"husky": "^7.0.4",
|
|
38
|
-
"karma": "^6.3.
|
|
44
|
+
"karma": "^6.3.9",
|
|
39
45
|
"karma-browserstack-launcher": "^1.6.0",
|
|
40
46
|
"karma-chrome-launcher": "^3.1.0",
|
|
41
|
-
"karma-firefox-launcher": "^2.1.
|
|
47
|
+
"karma-firefox-launcher": "^2.1.2",
|
|
42
48
|
"karma-mocha": "^2.0.1",
|
|
43
49
|
"karma-safari-launcher": "^1.0.0",
|
|
44
50
|
"karma-sinon-chai": "^2.0.2",
|
|
@@ -47,19 +53,20 @@
|
|
|
47
53
|
"load-grunt-config": "^4.0.1",
|
|
48
54
|
"midi-test": "^1.1.9",
|
|
49
55
|
"mocha": "^9.1.3",
|
|
50
|
-
"prettier": "^2.
|
|
51
|
-
"pretty-quick": "^3.1.
|
|
52
|
-
"rollup": "^2.
|
|
56
|
+
"prettier": "^2.5.1",
|
|
57
|
+
"pretty-quick": "^3.1.2",
|
|
58
|
+
"rollup": "^2.61.1",
|
|
53
59
|
"rxjs": "^7.4.0",
|
|
54
|
-
"rxjs-for-await": "0.0
|
|
60
|
+
"rxjs-for-await": "^1.0.0",
|
|
55
61
|
"sinon": "^11.1.2",
|
|
56
62
|
"sinon-chai": "^3.7.0",
|
|
63
|
+
"spect": "^23.1.1",
|
|
57
64
|
"ts-loader": "^9.2.6",
|
|
58
|
-
"tsconfig-holy-grail": "^11.1.
|
|
65
|
+
"tsconfig-holy-grail": "^11.1.19",
|
|
59
66
|
"tslint": "^6.1.3",
|
|
60
67
|
"tslint-config-holy-grail": "^53.2.25",
|
|
61
|
-
"typescript": "^4.
|
|
62
|
-
"webpack": "^5.
|
|
68
|
+
"typescript": "^4.5.4",
|
|
69
|
+
"webpack": "^5.65.0",
|
|
63
70
|
"xstream": "^11.14.0"
|
|
64
71
|
},
|
|
65
72
|
"files": [
|
|
@@ -88,5 +95,5 @@
|
|
|
88
95
|
"test": "grunt lint && grunt test"
|
|
89
96
|
},
|
|
90
97
|
"types": "build/es2019/module.d.ts",
|
|
91
|
-
"version": "2.0.
|
|
98
|
+
"version": "2.0.4"
|
|
92
99
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { Observer, Subscribable } from 'rxjs-interop';
|
|
1
2
|
import { TObserverParameters, TSubscribableThing, TSubscribeFunction, TWrapSubscribeFunctionFactory } from '../types';
|
|
2
3
|
|
|
3
4
|
export const createWrapSubscribeFunction: TWrapSubscribeFunctionFactory = (patch, toObserver) => {
|
|
4
5
|
const emptyFunction = () => {}; // tslint:disable-line:no-empty
|
|
6
|
+
const isNextFunction = <T>(args: TObserverParameters<T>): args is [Observer<T>['next']] => typeof args[0] === 'function';
|
|
5
7
|
|
|
6
8
|
return <T>(innerSubscribe: TSubscribeFunction<T>) => {
|
|
7
9
|
const subscribe = <TSubscribableThing<T>>((...args: TObserverParameters<T>) => {
|
|
8
|
-
const unsubscribe = innerSubscribe(toObserver(...args));
|
|
10
|
+
const unsubscribe = innerSubscribe(isNextFunction(args) ? toObserver({ next: args[0] }) : toObserver(...args));
|
|
9
11
|
|
|
10
12
|
if (unsubscribe !== undefined) {
|
|
11
13
|
return unsubscribe;
|
|
@@ -14,7 +16,9 @@ export const createWrapSubscribeFunction: TWrapSubscribeFunctionFactory = (patch
|
|
|
14
16
|
return emptyFunction;
|
|
15
17
|
});
|
|
16
18
|
|
|
17
|
-
subscribe[Symbol.observable] = () => ({
|
|
19
|
+
subscribe[Symbol.observable] = () => ({
|
|
20
|
+
subscribe: (...args: Parameters<Subscribable<T>['subscribe']>) => ({ unsubscribe: subscribe(...args) })
|
|
21
|
+
});
|
|
18
22
|
|
|
19
23
|
return patch(subscribe);
|
|
20
24
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Observer, Subscribable } from 'rxjs-interop';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
export type TObserverParameters<T> = Parameters<Subscribable<T>['subscribe']> | [PartialObserver<T>?];
|
|
3
|
+
export type TObserverParameters<T> = Parameters<Subscribable<T>['subscribe']> | [Observer<T>['next']];
|