ripple 0.2.53 → 0.2.55

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.
@@ -1,3 +1,4 @@
1
+ /** @import { Block, Tracked } from '#client' */
1
2
  import { get, increment, safe_scope, set, tracked } from './internal/client/runtime.js';
2
3
 
3
4
  const introspect_methods = ['entries', 'forEach', 'keys', 'values', Symbol.iterator];
@@ -8,14 +9,26 @@ const new_other_methods = ['difference', 'intersection', 'symmetricDifference',
8
9
 
9
10
  let init = false;
10
11
 
11
- export class RippleSet extends Set {
12
+ /**
13
+ * @template T
14
+ * @extends {Set<T>}
15
+ * @returns {TrackedSet<T>}
16
+ */
17
+ export class TrackedSet extends Set {
18
+ /** @type {Tracked} */
12
19
  #tracked_size;
20
+ /** @type {Map<T, Tracked>} */
13
21
  #tracked_items = new Map();
22
+ /** @type {Block} */
23
+ #block;
14
24
 
25
+ /**
26
+ * @param {Iterable<T>} iterable
27
+ */
15
28
  constructor(iterable) {
16
29
  super();
17
30
 
18
- var block = safe_scope();
31
+ var block = this.#block = safe_scope();
19
32
 
20
33
  if (iterable) {
21
34
  for (var item of iterable) {
@@ -24,7 +37,7 @@ export class RippleSet extends Set {
24
37
  }
25
38
  }
26
39
 
27
- this.#tracked_size = tracked(this.size, block);
40
+ this.#tracked_size = tracked(super.size, block);
28
41
 
29
42
  if (!init) {
30
43
  init = true;
@@ -33,7 +46,7 @@ export class RippleSet extends Set {
33
46
  }
34
47
 
35
48
  #init() {
36
- var proto = RippleSet.prototype;
49
+ var proto = TrackedSet.prototype;
37
50
  var set_proto = Set.prototype;
38
51
 
39
52
  for (const method of introspect_methods) {
@@ -41,8 +54,9 @@ export class RippleSet extends Set {
41
54
  continue;
42
55
  }
43
56
 
57
+ /** @param {...any} v */
44
58
  proto[method] = function (...v) {
45
- this.$size;
59
+ this.size;
46
60
 
47
61
  return set_proto[method].apply(this, v);
48
62
  };
@@ -54,10 +68,10 @@ export class RippleSet extends Set {
54
68
  }
55
69
 
56
70
  proto[method] = function (other, ...v) {
57
- this.$size;
71
+ this.size;
58
72
 
59
- if (other instanceof RippleSet) {
60
- other.$size;
73
+ if (other instanceof TrackedSet) {
74
+ other.size;
61
75
  }
62
76
 
63
77
  return set_proto[method].apply(this, [other, ...v]);
@@ -70,31 +84,39 @@ export class RippleSet extends Set {
70
84
  }
71
85
 
72
86
  proto[method] = function (other, ...v) {
73
- this.$size;
87
+ this.size;
74
88
 
75
- if (other instanceof RippleSet) {
76
- other.$size;
89
+ if (other instanceof TrackedSet) {
90
+ other.size;
77
91
  }
78
92
 
79
- return new RippleSet(set_proto[method].apply(this, [other, ...v]));
93
+ return new TrackedSet(set_proto[method].apply(this, [other, ...v]));
80
94
  };
81
95
  }
82
96
  }
83
97
 
98
+ /**
99
+ * @param {T} value
100
+ * @returns {this}
101
+ */
84
102
  add(value) {
85
- var block = safe_scope();
103
+ var block = this.#block;
86
104
 
87
105
  if (!super.has(value)) {
88
106
  super.add(value);
89
107
  this.#tracked_items.set(value, tracked(0, block));
90
- set(this.#tracked_size, this.size, block);
108
+ set(this.#tracked_size, super.size, block);
91
109
  }
92
110
 
93
111
  return this;
94
112
  }
95
113
 
114
+ /**
115
+ * @param {T} value
116
+ * @returns {boolean}
117
+ */
96
118
  delete(value) {
97
- var block = safe_scope();
119
+ var block = this.#block;
98
120
 
99
121
  if (!super.delete(value)) {
100
122
  return false;
@@ -104,13 +126,17 @@ export class RippleSet extends Set {
104
126
 
105
127
  increment(t, block);
106
128
  this.#tracked_items.delete(value);
107
- set(this.#tracked_size, this.size, block);
129
+ set(this.#tracked_size, super.size, block);
108
130
 
109
131
  return true;
110
132
  }
111
133
 
134
+ /**
135
+ * @param {T} value
136
+ * @return {boolean}
137
+ */
112
138
  has(value) {
113
- var block = safe_scope();
139
+
114
140
  var has = super.has(value);
115
141
  var tracked_items = this.#tracked_items;
116
142
  var t = tracked_items.get(value);
@@ -120,7 +146,7 @@ export class RippleSet extends Set {
120
146
  // It's not possible to have a disconnect, we track each value
121
147
  // If the value doesn't exist, track the size in case it's added later
122
148
  // but don't create tracked entries willy-nilly to track all possible values
123
- this.$size;
149
+ this.size;
124
150
  } else {
125
151
  get(t);
126
152
  }
@@ -129,7 +155,7 @@ export class RippleSet extends Set {
129
155
  }
130
156
 
131
157
  clear() {
132
- var block = safe_scope();
158
+ var block = this.#block;
133
159
 
134
160
  if (super.size === 0) {
135
161
  return;
@@ -144,12 +170,12 @@ export class RippleSet extends Set {
144
170
  set(this.#tracked_size, 0, block);
145
171
  }
146
172
 
147
- get $size() {
173
+ get size() {
148
174
  return get(this.#tracked_size);
149
175
  }
150
176
 
151
177
  toJSON() {
152
- this.$size;
178
+ this.size;
153
179
 
154
180
  return [...this];
155
181
  }