@webkrafters/react-eagleeye 1.1.0-alpha.17 → 1.1.0-alpha.19

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.
@@ -40,6 +40,7 @@ interface Entry {
40
40
  }
41
41
  interface Handle<W extends WeakKey> {
42
42
  readonly resource: W;
43
+ release(force: boolean): void;
43
44
  }
44
45
  declare class ObserverHandle<W extends AbstractObservable<ObservableTemplate<W>>> implements Handle<W> {
45
46
  private _wObs;
@@ -63,6 +64,7 @@ declare class StreamerHandle<W extends Channel> implements Handle<W> {
63
64
  get size(): number;
64
65
  dec(): void;
65
66
  inc(): void;
67
+ release(force?: boolean): void;
66
68
  }
67
69
  interface IResource<W extends WeakKey> {
68
70
  acquire(desc: string, resource: W): Handle<W>;
@@ -123,27 +123,24 @@ var StreamerHandle = /*#__PURE__*/function () {
123
123
  }, {
124
124
  key: "dec",
125
125
  value: function dec() {
126
- if (!this.isValid) {
127
- return;
128
- }
129
- this._entry.numConnections--;
130
- if (this.size) {
126
+ this.size > 0 && this._entry.numConnections--;
127
+ }
128
+ }, {
129
+ key: "inc",
130
+ value: function inc() {
131
+ this.isValid && this._entry.numConnections++;
132
+ }
133
+ }, {
134
+ key: "release",
135
+ value: function release() {
136
+ var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
137
+ if (!force && this.size > 0) {
131
138
  return;
132
139
  }
133
140
  this.resource.endStream();
134
141
  this._chs.finalizer.unregister(this.resource);
135
- var channel = this._entry.channel;
136
142
  this._entry.channel = null;
137
143
  this._chs.finalize(this._sMapHash);
138
- setTimeout(function () {
139
- var _channel$deref;
140
- return (_channel$deref = channel.deref()) === null || _channel$deref === void 0 ? void 0 : _channel$deref.endStream();
141
- }, 0);
142
- }
143
- }, {
144
- key: "inc",
145
- value: function inc() {
146
- this.isValid && this._entry.numConnections++;
147
144
  }
148
145
  }]);
149
146
  }();
@@ -419,16 +416,18 @@ var ObservableUniverse = exports.ObservableUniverse = /*#__PURE__*/function () {
419
416
  ctxHandle.addChannelAt(sMapHash, ctxHandle.resource.stream(selectorMap));
420
417
  streamHandle = ctxHandle.getChannelHandleAt(sMapHash);
421
418
  }
422
- streamHandle.inc();
423
419
  return streamHandle;
424
420
  }, [sMapHash, targetId]);
425
421
  var mounted = (0, _react.useRef)(false);
426
- var _useState3 = (0, _react.useState)(function () {
422
+ var _useState3 = (0, _react.useState)(getCurrentUri),
423
+ _useState4 = _slicedToArray(_useState3, 1),
424
+ currentUri = _useState4[0];
425
+ var _useState5 = (0, _react.useState)(function () {
427
426
  return (0, _.makeStore)(handle.resource);
428
427
  }),
429
- _useState4 = _slicedToArray(_useState3, 2),
430
- store = _useState4[0],
431
- setStore = _useState4[1];
428
+ _useState6 = _slicedToArray(_useState5, 2),
429
+ store = _useState6[0],
430
+ setStore = _useState6[1];
432
431
  (0, _react.useEffect)(function () {
433
432
  var channel = handle.resource;
434
433
  if (mounted.current) {
@@ -442,9 +441,13 @@ var ObservableUniverse = exports.ObservableUniverse = /*#__PURE__*/function () {
442
441
  }));
443
442
  };
444
443
  channel.addListener('data-changed', fn);
444
+ handle.inc();
445
445
  return function () {
446
446
  channel.removeListener('data-changed', fn);
447
447
  handle.dec();
448
+ var uri = getCurrentUri();
449
+ currentUri === uri && handle.release();
450
+ currentUri = uri;
448
451
  };
449
452
  }, [handle.resource]);
450
453
  return store;
@@ -452,6 +455,10 @@ var ObservableUniverse = exports.ObservableUniverse = /*#__PURE__*/function () {
452
455
  }
453
456
  }]);
454
457
  }();
458
+ function getCurrentUri() {
459
+ var _globalThis$location;
460
+ return (_globalThis$location = globalThis.location) === null || _globalThis$location === void 0 ? void 0 : _globalThis$location.pathname;
461
+ }
455
462
  var Utility = exports.Utility = /*#__PURE__*/function () {
456
463
  function Utility(context) {
457
464
  _classCallCheck(this, Utility);
package/package.json CHANGED
@@ -126,7 +126,7 @@
126
126
  "test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
127
127
  },
128
128
  "types": "dist/index.d.ts",
129
- "version": "1.1.0-alpha.17",
129
+ "version": "1.1.0-alpha.19",
130
130
  "dependencies": {
131
131
  "@webkrafters/eagleeye": "^1.0.8",
132
132
  "js-sha512": "^0.9.0",