@civet/core 1.2.5 → 1.2.7

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/lib/Notifier.js CHANGED
@@ -14,26 +14,22 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
14
14
  var Notifier = /*#__PURE__*/_createClass(function Notifier() {
15
15
  var _this = this;
16
16
  _classCallCheck(this, Notifier);
17
- _defineProperty(this, "subscriptions", []);
17
+ _defineProperty(this, "listeners", new Set());
18
18
  _defineProperty(this, "subscribe", function (handler) {
19
19
  if (typeof handler !== 'function') throw new Error('Handler must be a function');
20
- if (!_this.isSubscribed(handler)) {
21
- _this.subscriptions.push(handler);
22
- }
20
+ _this.listeners.add(handler);
23
21
  return function () {
24
- _this.subscriptions = _this.subscriptions.filter(function (item) {
25
- return item !== handler;
26
- });
22
+ _this.listeners["delete"](handler);
27
23
  };
28
24
  });
29
25
  _defineProperty(this, "isSubscribed", function (handler) {
30
- return _this.subscriptions.includes(handler);
26
+ return _this.listeners.has(handler);
31
27
  });
32
28
  _defineProperty(this, "trigger", function () {
33
29
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
34
30
  args[_key] = arguments[_key];
35
31
  }
36
- _this.subscriptions.forEach(function (handler) {
32
+ _this.listeners.forEach(function (handler) {
37
33
  return handler.apply(void 0, args);
38
34
  });
39
35
  });
@@ -58,7 +58,7 @@ function useResource(_ref) {
58
58
  setInstance = _React$useState4[1];
59
59
  _react["default"].useEffect(function () {
60
60
  var i = dataProvider.createInstance();
61
- setInstance(i);
61
+ setInstance(i !== null && i !== void 0 ? i : {});
62
62
  return function () {
63
63
  dataProvider.releaseInstance(i);
64
64
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civet/core",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "Civet",
5
5
  "main": "./lib/index.js",
6
6
  "scripts": {
package/src/Notifier.js CHANGED
@@ -1,20 +1,18 @@
1
1
  class Notifier {
2
- subscriptions = [];
2
+ listeners = new Set();
3
3
 
4
4
  subscribe = (handler) => {
5
5
  if (typeof handler !== 'function') throw new Error('Handler must be a function');
6
- if (!this.isSubscribed(handler)) {
7
- this.subscriptions.push(handler);
8
- }
6
+ this.listeners.add(handler);
9
7
  return () => {
10
- this.subscriptions = this.subscriptions.filter((item) => item !== handler);
8
+ this.listeners.delete(handler);
11
9
  };
12
10
  };
13
11
 
14
- isSubscribed = (handler) => this.subscriptions.includes(handler);
12
+ isSubscribed = (handler) => this.listeners.has(handler);
15
13
 
16
14
  trigger = (...args) => {
17
- this.subscriptions.forEach((handler) => handler(...args));
15
+ this.listeners.forEach((handler) => handler(...args));
18
16
  };
19
17
  }
20
18
 
@@ -36,7 +36,7 @@ function useResource({
36
36
  const [instance, setInstance] = React.useState();
37
37
  React.useEffect(() => {
38
38
  const i = dataProvider.createInstance();
39
- setInstance(i);
39
+ setInstance(i ?? {});
40
40
  return () => {
41
41
  dataProvider.releaseInstance(i);
42
42
  };