subscribable-things 2.1.6 → 2.1.8

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 CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  **A collection of reactive wrappers for various browser APIs.**
6
6
 
7
- [![dependencies](https://img.shields.io/david/chrisguttandin/subscribable-things.svg?style=flat-square)](https://github.com/chrisguttandin/subscribable-things/network/dependencies)
8
7
  [![version](https://img.shields.io/npm/v/subscribable-things.svg?style=flat-square)](https://www.npmjs.com/package/subscribable-things)
9
8
 
10
9
  This package provides factory functions which can be used to turn browser APIs into subscribable things. A subscribable thing can either be consumed directly with callback functions or by utilzing one of the popular libraries for reactive programming.
@@ -14,7 +14,6 @@
14
14
  if (window === null || window.cancelAnimationFrame === undefined || window.requestAnimationFrame === undefined) {
15
15
  return emitNotSupportedError(observer);
16
16
  }
17
-
18
17
  var animationFrameHandle = window.requestAnimationFrame(function animationFrameCallback(timestamp) {
19
18
  animationFrameHandle = window.requestAnimationFrame(animationFrameCallback);
20
19
  observer.next(timestamp);
@@ -31,7 +30,6 @@
31
30
  var getAttribute = function getAttribute() {
32
31
  return htmlElement.getAttribute(name);
33
32
  };
34
-
35
33
  return prependSubscribableThing(mapSubscribableThing(mutations(htmlElement, {
36
34
  attributeFilter: [name],
37
35
  childList: false,
@@ -48,7 +46,6 @@
48
46
  if (window === null || window.navigator === undefined || window.navigator.geolocation === undefined || window.navigator.geolocation.clearWatch === undefined || window.navigator.geolocation.watchPosition === undefined) {
49
47
  return emitNotSupportedError(observer);
50
48
  }
51
-
52
49
  var watchId = window.navigator.geolocation.watchPosition(function (position) {
53
50
  return observer.next(position);
54
51
  }, function (err) {
@@ -67,17 +64,14 @@
67
64
  if (window === null || window.IntersectionObserver === undefined) {
68
65
  return emitNotSupportedError(observer);
69
66
  }
70
-
71
67
  var intersectionObserverObserver = new window.IntersectionObserver(function (entries) {
72
68
  return observer.next(entries);
73
69
  }, options);
74
-
75
70
  try {
76
71
  intersectionObserverObserver.observe(htmlElement);
77
72
  } catch (err) {
78
73
  observer.error(err);
79
74
  }
80
-
81
75
  return function () {
82
76
  return intersectionObserverObserver.disconnect();
83
77
  };
@@ -86,9 +80,7 @@
86
80
  };
87
81
 
88
82
  function ownKeys$1(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; }
89
-
90
83
  function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
91
-
92
84
  var createMapSubscribableThing = function createMapSubscribableThing(wrapSubscribeFunction) {
93
85
  return function (subscribableThing, map) {
94
86
  return wrapSubscribeFunction(function (observer) {
@@ -107,9 +99,7 @@
107
99
  if (window === null || window.navigator === undefined || window.navigator.mediaDevices === undefined || window.navigator.mediaDevices.enumerateDevices === undefined) {
108
100
  return emitNotSupportedError(observer);
109
101
  }
110
-
111
102
  var isActive = true;
112
-
113
103
  var enumerateDevices = function enumerateDevices() {
114
104
  window.navigator.mediaDevices.enumerateDevices().then(function (mediaDevices) {
115
105
  if (isActive) {
@@ -122,12 +112,10 @@
122
112
  }
123
113
  });
124
114
  };
125
-
126
115
  var unsubscribe = function unsubscribe() {
127
116
  isActive = false;
128
117
  window.navigator.mediaDevices.removeEventListener('devicechange', enumerateDevices);
129
118
  };
130
-
131
119
  enumerateDevices();
132
120
  window.navigator.mediaDevices.addEventListener('devicechange', enumerateDevices);
133
121
  return unsubscribe;
@@ -141,14 +129,11 @@
141
129
  if (window === null || window.matchMedia === undefined) {
142
130
  return emitNotSupportedError(observer);
143
131
  }
144
-
145
132
  var mediaQueryList = window.matchMedia(mediaQueryString);
146
133
  observer.next(mediaQueryList.matches);
147
-
148
134
  mediaQueryList.onchange = function () {
149
135
  return observer.next(mediaQueryList.matches);
150
136
  };
151
-
152
137
  return function () {
153
138
  mediaQueryList.onchange = null;
154
139
  };
@@ -162,17 +147,14 @@
162
147
  if (window === null || window.PerformanceObserver === undefined) {
163
148
  return emitNotSupportedError(observer);
164
149
  }
165
-
166
150
  var performanceObserver = new window.PerformanceObserver(function (entryList) {
167
151
  return observer.next(entryList.getEntries());
168
152
  });
169
-
170
153
  try {
171
154
  performanceObserver.observe(options);
172
155
  } catch (err) {
173
156
  observer.error(err);
174
157
  }
175
-
176
158
  return function () {
177
159
  return performanceObserver.disconnect();
178
160
  };
@@ -184,10 +166,8 @@
184
166
  return function (midiAccess) {
185
167
  return wrapSubscribeFunction(function (observer) {
186
168
  var midiInputs = Array.from(midiAccess.inputs.values());
187
-
188
169
  var emitMidiInputs = function emitMidiInputs() {
189
170
  var midiAccessInputs = midiAccess.inputs;
190
-
191
171
  if (midiInputs.length !== midiAccessInputs.size || midiInputs.some(function (_ref) {
192
172
  var id = _ref.id;
193
173
  return !midiAccessInputs.has(id);
@@ -196,7 +176,6 @@
196
176
  observer.next(midiInputs);
197
177
  }
198
178
  };
199
-
200
179
  observer.next(midiInputs);
201
180
  midiAccess.addEventListener('statechange', emitMidiInputs);
202
181
  return function () {
@@ -210,10 +189,8 @@
210
189
  return function (midiAccess) {
211
190
  return wrapSubscribeFunction(function (observer) {
212
191
  var midiOutputs = Array.from(midiAccess.outputs.values());
213
-
214
192
  var emitMidiOutputs = function emitMidiOutputs() {
215
193
  var midiAccessOutputs = midiAccess.outputs;
216
-
217
194
  if (midiOutputs.length !== midiAccessOutputs.size || midiOutputs.some(function (_ref) {
218
195
  var id = _ref.id;
219
196
  return !midiAccessOutputs.has(id);
@@ -222,7 +199,6 @@
222
199
  observer.next(midiOutputs);
223
200
  }
224
201
  };
225
-
226
202
  observer.next(midiOutputs);
227
203
  midiAccess.addEventListener('statechange', emitMidiOutputs);
228
204
  return function () {
@@ -238,17 +214,14 @@
238
214
  if (window === null || window.MutationObserver === undefined) {
239
215
  return emitNotSupportedError(observer);
240
216
  }
241
-
242
217
  var mutationObserver = new window.MutationObserver(function (records) {
243
218
  return observer.next(records);
244
219
  });
245
-
246
220
  try {
247
221
  mutationObserver.observe(htmlElement, options);
248
222
  } catch (err) {
249
223
  observer.error(err);
250
224
  }
251
-
252
225
  return function () {
253
226
  return mutationObserver.disconnect();
254
227
  };
@@ -262,7 +235,6 @@
262
235
  var listener = function listener(event) {
263
236
  return observer.next(event);
264
237
  };
265
-
266
238
  target.addEventListener(type, listener, options);
267
239
  return function () {
268
240
  return target.removeEventListener(type, listener, options);
@@ -277,15 +249,12 @@
277
249
  if (window === null || window.navigator === undefined || window.navigator.onLine === undefined) {
278
250
  return emitNotSupportedError(observer);
279
251
  }
280
-
281
252
  var emitFalse = function emitFalse() {
282
253
  return observer.next(false);
283
254
  };
284
-
285
255
  var emitTrue = function emitTrue() {
286
256
  return observer.next(true);
287
257
  };
288
-
289
258
  window.addEventListener('offline', emitFalse);
290
259
  window.addEventListener('online', emitTrue);
291
260
  observer.next(window.navigator.onLine);
@@ -303,23 +272,18 @@
303
272
  if (window === null || window.navigator === undefined || window.navigator.permissions === undefined || window.navigator.permissions.query === undefined) {
304
273
  return emitNotSupportedError(observer);
305
274
  }
306
-
307
275
  var isActive = true;
308
-
309
276
  var unsubscribe = function unsubscribe() {
310
277
  isActive = false;
311
278
  };
312
-
313
279
  window.navigator.permissions.query(permissionDescriptor).then(function (permissionStatus) {
314
280
  if (isActive) {
315
281
  observer.next(permissionStatus.state);
316
282
  }
317
-
318
283
  if (isActive) {
319
284
  permissionStatus.onchange = function () {
320
285
  return observer.next(permissionStatus.state);
321
286
  };
322
-
323
287
  unsubscribe = function unsubscribe() {
324
288
  permissionStatus.onchange = null;
325
289
  };
@@ -351,7 +315,6 @@
351
315
  if (window === null || window.ReportingObserver === undefined) {
352
316
  return emitNotSupportedError(observer);
353
317
  }
354
-
355
318
  var reportingObserver = new window.ReportingObserver(function (reportList) {
356
319
  return observer.next(reportList);
357
320
  }, options);
@@ -369,17 +332,14 @@
369
332
  if (window === null || window.ResizeObserver === undefined) {
370
333
  return emitNotSupportedError(observer);
371
334
  }
372
-
373
335
  var resizeObserver = new window.ResizeObserver(function (entries) {
374
336
  return observer.next(entries);
375
337
  });
376
-
377
338
  try {
378
339
  resizeObserver.observe(htmlElement, options);
379
340
  } catch (err) {
380
341
  observer.error(err);
381
342
  }
382
-
383
343
  return function () {
384
344
  return resizeObserver.disconnect();
385
345
  };
@@ -393,54 +353,44 @@
393
353
  if (window === null || window.clearInterval === undefined || window.setInterval === undefined) {
394
354
  return emitNotSupportedError(observer);
395
355
  }
396
-
397
356
  var possiblyUnhandledRejections = new Map();
398
357
  var intervalId = null;
399
-
400
358
  var deletePossiblyUnhandledRejection = function deletePossiblyUnhandledRejection(_ref) {
401
359
  var promise = _ref.promise;
402
360
  return possiblyUnhandledRejections["delete"](promise);
403
361
  };
404
-
405
362
  var emitUnhandledRejection = function emitUnhandledRejection() {
406
363
  var latestTimestampToEmit = Date.now() - coolingOffPeriod;
407
364
  possiblyUnhandledRejections.forEach(function (_ref2, promise) {
408
365
  var reason = _ref2.reason,
409
- timestamp = _ref2.timestamp;
410
-
366
+ timestamp = _ref2.timestamp;
411
367
  if (timestamp > latestTimestampToEmit) {
412
368
  return;
413
369
  }
414
-
415
370
  possiblyUnhandledRejections["delete"](promise);
416
371
  observer.next(reason);
417
372
  });
418
-
419
373
  if (intervalId !== null && possiblyUnhandledRejections.size === 0) {
420
374
  window.clearInterval(intervalId);
421
375
  intervalId = null;
422
376
  }
423
377
  };
424
-
425
378
  var registerPossiblyUnhandledRejection = function registerPossiblyUnhandledRejection(event) {
426
379
  event.preventDefault();
427
380
  possiblyUnhandledRejections.set(event.promise, {
428
381
  reason: event.reason,
429
382
  timestamp: Date.now()
430
383
  });
431
-
432
384
  if (intervalId === null) {
433
385
  intervalId = window.setInterval(emitUnhandledRejection, coolingOffPeriod / 2);
434
386
  }
435
387
  };
436
-
437
388
  window.addEventListener('rejectionhandled', deletePossiblyUnhandledRejection);
438
389
  window.addEventListener('unhandledrejection', registerPossiblyUnhandledRejection);
439
390
  return function () {
440
391
  if (intervalId !== null) {
441
392
  window.clearInterval(intervalId);
442
393
  }
443
-
444
394
  window.removeEventListener('rejectionhandled', deletePossiblyUnhandledRejection);
445
395
  window.removeEventListener('unhandledrejection', registerPossiblyUnhandledRejection);
446
396
  };
@@ -449,16 +399,13 @@
449
399
  };
450
400
 
451
401
  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; }
452
-
453
402
  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; }
454
-
455
403
  var createVideoFrame = function createVideoFrame(emitNotSupportedError, wrapSubscribeFunction) {
456
404
  return function (videoElement) {
457
405
  return wrapSubscribeFunction(function (observer) {
458
406
  if (videoElement.cancelVideoFrameCallback === undefined || videoElement.requestVideoFrameCallback === undefined) {
459
407
  return emitNotSupportedError(observer);
460
408
  }
461
-
462
409
  var videoFrameHandle = videoElement.requestVideoFrameCallback(function videoFrameCallback(now, metadata) {
463
410
  videoFrameHandle = videoElement.requestVideoFrameCallback(videoFrameCallback);
464
411
  observer.next(_objectSpread(_objectSpread({}, metadata), {}, {
@@ -478,30 +425,24 @@
478
425
  if (window === null || window.navigator === undefined || window.navigator.wakeLock === undefined) {
479
426
  return emitNotSupportedError(observer);
480
427
  }
481
-
482
428
  var releaseWakeLock = function releaseWakeLock(wakeLockSentinel) {
483
- return wakeLockSentinel.release()["catch"](function () {// Ignore errors.
429
+ return wakeLockSentinel.release()["catch"](function () {
430
+ // Ignore errors.
484
431
  });
485
432
  };
486
-
487
433
  var removeReleaseEventListener = function removeReleaseEventListener(wakeLockSentinel) {
488
434
  wakeLockSentinel.onrelease = null;
489
435
  };
490
-
491
436
  var isActive = true;
492
-
493
437
  var unsubscribeWhileRequesting = function unsubscribeWhileRequesting() {
494
438
  isActive = false;
495
439
  };
496
-
497
440
  var unsubscribe = unsubscribeWhileRequesting;
498
-
499
441
  var requestWakeLock = function requestWakeLock() {
500
442
  return window.navigator.wakeLock.request(type).then(function (wakeLockSentinel) {
501
443
  if (isActive) {
502
444
  observer.next(true);
503
445
  }
504
-
505
446
  if (isActive) {
506
447
  wakeLockSentinel.onrelease = function () {
507
448
  observer.next(false);
@@ -509,7 +450,6 @@
509
450
  removeReleaseEventListener(wakeLockSentinel);
510
451
  requestWakeLock();
511
452
  };
512
-
513
453
  unsubscribe = function unsubscribe() {
514
454
  removeReleaseEventListener(wakeLockSentinel);
515
455
  releaseWakeLock(wakeLockSentinel);
@@ -523,7 +463,6 @@
523
463
  }
524
464
  });
525
465
  };
526
-
527
466
  requestWakeLock();
528
467
  return function () {
529
468
  return unsubscribe();
@@ -539,29 +478,22 @@
539
478
 
540
479
  var createWrapSubscribeFunction = function createWrapSubscribeFunction(patch, toObserver) {
541
480
  var emptyFunction = function emptyFunction() {}; // tslint:disable-line:no-empty
542
-
543
-
544
481
  var isNextFunction = function isNextFunction(args) {
545
482
  return typeof args[0] === 'function';
546
483
  };
547
-
548
484
  return function (innerSubscribe) {
549
485
  var _subscribe = function subscribe() {
550
486
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
551
487
  args[_key] = arguments[_key];
552
488
  }
553
-
554
489
  var unsubscribe = innerSubscribe(isNextFunction(args) ? toObserver({
555
490
  next: args[0]
556
491
  }) : toObserver.apply(void 0, args));
557
-
558
492
  if (unsubscribe !== undefined) {
559
493
  return unsubscribe;
560
494
  }
561
-
562
495
  return emptyFunction;
563
496
  };
564
-
565
497
  _subscribe[Symbol.observable] = function () {
566
498
  return {
567
499
  subscribe: function subscribe() {
@@ -571,7 +503,6 @@
571
503
  }
572
504
  };
573
505
  };
574
-
575
506
  return patch(_subscribe);
576
507
  };
577
508
  };
package/package.json CHANGED
@@ -15,33 +15,33 @@
15
15
  }
16
16
  ],
17
17
  "dependencies": {
18
- "@babel/runtime": "^7.18.9",
18
+ "@babel/runtime": "^7.19.4",
19
19
  "rxjs-interop": "^2.0.0",
20
20
  "tslib": "^2.4.0"
21
21
  },
22
22
  "description": "A collection of reactive wrappers for various browser APIs.",
23
23
  "devDependencies": {
24
- "@babel/core": "^7.18.9",
24
+ "@babel/core": "^7.19.6",
25
25
  "@babel/plugin-external-helpers": "^7.18.6",
26
- "@babel/plugin-transform-runtime": "^7.18.9",
27
- "@babel/preset-env": "^7.18.9",
28
- "@commitlint/cli": "^17.0.3",
29
- "@commitlint/config-angular": "^17.0.3",
26
+ "@babel/plugin-transform-runtime": "^7.19.6",
27
+ "@babel/preset-env": "^7.19.4",
28
+ "@commitlint/cli": "^17.1.2",
29
+ "@commitlint/config-angular": "^17.1.0",
30
30
  "@rollup/plugin-babel": "^5.3.1",
31
31
  "baconjs": "^3.0.17",
32
- "body-parser": "^1.20.0",
32
+ "body-parser": "^1.20.1",
33
33
  "callbag-basics": "^4.0.0",
34
34
  "chai": "^4.3.6",
35
35
  "commitizen": "^4.2.5",
36
36
  "cz-conventional-changelog": "^3.3.0",
37
- "eslint": "^8.20.0",
38
- "eslint-config-holy-grail": "^52.0.22",
37
+ "eslint": "^8.26.0",
38
+ "eslint-config-holy-grail": "^52.0.33",
39
39
  "grunt": "^1.5.3",
40
40
  "grunt-cli": "^1.4.3",
41
41
  "grunt-sh": "^0.2.0",
42
42
  "husky": "^8.0.1",
43
- "hyperf": "^1.3.0",
44
- "karma": "^6.4.0",
43
+ "hyperf": "^1.4.0",
44
+ "karma": "^6.4.1",
45
45
  "karma-browserstack-launcher": "^1.6.0",
46
46
  "karma-chrome-launcher": "^3.1.1",
47
47
  "karma-firefox-launcher": "^2.1.2",
@@ -52,21 +52,21 @@
52
52
  "kefir": "^3.8.8",
53
53
  "load-grunt-config": "^4.0.1",
54
54
  "midi-test": "^1.2.1",
55
- "mocha": "^10.0.0",
55
+ "mocha": "^10.1.0",
56
56
  "prettier": "^2.7.1",
57
57
  "pretty-quick": "^3.1.3",
58
58
  "rimraf": "^3.0.2",
59
- "rollup": "^2.77.0",
60
- "rxjs": "^7.5.6",
59
+ "rollup": "^2.79.1",
60
+ "rxjs": "^7.5.7",
61
61
  "rxjs-for-await": "^1.0.0",
62
- "sinon": "^14.0.0",
62
+ "sinon": "^14.0.1",
63
63
  "sinon-chai": "^3.7.0",
64
- "ts-loader": "^9.3.1",
65
- "tsconfig-holy-grail": "^11.1.34",
64
+ "ts-loader": "^9.4.1",
65
+ "tsconfig-holy-grail": "^11.1.36",
66
66
  "tslint": "^6.1.3",
67
- "tslint-config-holy-grail": "^53.2.30",
68
- "typescript": "^4.7.4",
69
- "webpack": "^5.73.0",
67
+ "tslint-config-holy-grail": "^53.2.33",
68
+ "typescript": "^4.8.4",
69
+ "webpack": "^5.74.0",
70
70
  "xstream": "^11.14.0"
71
71
  },
72
72
  "files": [
@@ -95,5 +95,5 @@
95
95
  "test": "grunt lint && grunt test"
96
96
  },
97
97
  "types": "build/es2019/module.d.ts",
98
- "version": "2.1.6"
98
+ "version": "2.1.8"
99
99
  }