@limitlesspc/konbini 1.0.0 → 1.0.2

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/dist/index.cjs CHANGED
@@ -24,14 +24,13 @@ __export(index_exports, {
24
24
  konbini: () => konbini
25
25
  });
26
26
  module.exports = __toCommonJS(index_exports);
27
- var computationStack = [];
27
+ var outerCompute;
28
28
  function konbini(value) {
29
- const subscribers = [];
29
+ const subscribers = /* @__PURE__ */ new Set();
30
30
  const store = (...args) => {
31
31
  if (!args.length) {
32
- const outerCompute = computationStack.at(-1);
33
32
  if (outerCompute) {
34
- subscribers.push(outerCompute);
33
+ subscribers.add(outerCompute);
35
34
  }
36
35
  return value;
37
36
  }
@@ -47,12 +46,9 @@ function konbini(value) {
47
46
  store.set = (newValue) => store(newValue);
48
47
  store.subscribe = (subscriber) => {
49
48
  subscriber(value);
50
- subscribers.push(subscriber);
49
+ subscribers.add(subscriber);
51
50
  return () => {
52
- const index = subscribers.indexOf(subscriber);
53
- if (index !== -1) {
54
- subscribers.splice(index, 1);
55
- }
51
+ subscribers.delete(subscriber);
56
52
  };
57
53
  };
58
54
  return store;
@@ -63,9 +59,10 @@ function computed(fn) {
63
59
  const result = fn();
64
60
  store(result);
65
61
  }
66
- computationStack.push(compute);
62
+ const prevOuterCompute = outerCompute;
63
+ outerCompute = compute;
67
64
  compute();
68
- computationStack.pop();
65
+ outerCompute = prevOuterCompute;
69
66
  return store;
70
67
  }
71
68
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js CHANGED
@@ -1,12 +1,11 @@
1
1
  // index.ts
2
- var computationStack = [];
2
+ var outerCompute;
3
3
  function konbini(value) {
4
- const subscribers = [];
4
+ const subscribers = /* @__PURE__ */ new Set();
5
5
  const store = (...args) => {
6
6
  if (!args.length) {
7
- const outerCompute = computationStack.at(-1);
8
7
  if (outerCompute) {
9
- subscribers.push(outerCompute);
8
+ subscribers.add(outerCompute);
10
9
  }
11
10
  return value;
12
11
  }
@@ -22,12 +21,9 @@ function konbini(value) {
22
21
  store.set = (newValue) => store(newValue);
23
22
  store.subscribe = (subscriber) => {
24
23
  subscriber(value);
25
- subscribers.push(subscriber);
24
+ subscribers.add(subscriber);
26
25
  return () => {
27
- const index = subscribers.indexOf(subscriber);
28
- if (index !== -1) {
29
- subscribers.splice(index, 1);
30
- }
26
+ subscribers.delete(subscriber);
31
27
  };
32
28
  };
33
29
  return store;
@@ -38,9 +34,10 @@ function computed(fn) {
38
34
  const result = fn();
39
35
  store(result);
40
36
  }
41
- computationStack.push(compute);
37
+ const prevOuterCompute = outerCompute;
38
+ outerCompute = compute;
42
39
  compute();
43
- computationStack.pop();
40
+ outerCompute = prevOuterCompute;
44
41
  return store;
45
42
  }
46
43
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@limitlesspc/konbini",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
5
  "description": "Convenient stores",
6
6
  "license": "MIT",
7
7
  "repository": {