ripple 0.2.49 → 0.2.50

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,5 +1,5 @@
1
1
  import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
- import { mount, flushSync, RippleMap } from 'ripple';
2
+ import { mount, flushSync, RippleMap, track } from 'ripple';
3
3
 
4
4
  describe('RippleMap', () => {
5
5
  let container;
@@ -23,16 +23,16 @@ describe('RippleMap', () => {
23
23
  it('handles set with update and delete operations with a reactive $size var', () => {
24
24
  component MapTest() {
25
25
  let map = new RippleMap([['a', 1], ['b', 2], ['c', 3]]);
26
- let $value = map.get('a');
27
- let $size = map.$size;
26
+ let value = track(() => map.get('a'));
27
+ let size = track(() => map.$size);
28
28
 
29
29
  <button onClick={() => map.set('d', 4)}>{'set'}</button>
30
30
  <button onClick={() => map.delete('b')}>{'delete'}</button>
31
31
  <button onClick={() => map.set('a', 5)}>{'update'}</button>
32
32
 
33
33
  <pre>{map.get('d')}</pre>
34
- <pre>{$size}</pre>
35
- <pre>{$value}</pre>
34
+ <pre>{@size}</pre>
35
+ <pre>{@value}</pre>
36
36
  }
37
37
 
38
38
  render(MapTest);
@@ -80,10 +80,10 @@ describe('RippleMap', () => {
80
80
  it('handles has operation and tracks reactive $has', () => {
81
81
  component MapTest() {
82
82
  let map = new RippleMap([['a', 1], ['b', 2], ['c', 3]]);
83
- let $has = map.has('b');
83
+ let has = track(() => map.has('b'));
84
84
 
85
85
  <button onClick={() => map.delete('b')}>{'delete'}</button>
86
- <pre>{$has}</pre>
86
+ <pre>{@has}</pre>
87
87
  }
88
88
 
89
89
  render(MapTest);
@@ -100,15 +100,15 @@ describe('RippleMap', () => {
100
100
  it('handles reactivity of keys, values, and entries', () => {
101
101
  component MapTest() {
102
102
  let map = new RippleMap([['x', 10], ['y', 20]]);
103
- let $keys = Array.from(map.keys());
104
- let $values = Array.from(map.values());
105
- let $entries = Array.from(map.entries());
103
+ let keys = track(() => Array.from(map.keys()));
104
+ let values = track(() => Array.from(map.values()));
105
+ let entries = track(() => Array.from(map.entries()));
106
106
 
107
107
  <button onClick={() => map.delete('x')}>{'delete'}</button>
108
108
 
109
- <pre>{JSON.stringify($keys)}</pre>
110
- <pre>{JSON.stringify($values)}</pre>
111
- <pre>{JSON.stringify($entries)}</pre>
109
+ <pre>{JSON.stringify(@keys)}</pre>
110
+ <pre>{JSON.stringify(@values)}</pre>
111
+ <pre>{JSON.stringify(@entries)}</pre>
112
112
  }
113
113
 
114
114
  render(MapTest);
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
- import { mount, flushSync, RippleSet } from 'ripple';
2
+ import { mount, flushSync, RippleSet, track } from 'ripple';
3
3
 
4
4
  describe('RippleSet', () => {
5
5
  let container;
@@ -79,10 +79,10 @@ describe('RippleSet', () => {
79
79
  it('handles has operation', () => {
80
80
  component SetTest() {
81
81
  let items = new RippleSet([1, 2, 3]);
82
- let $hasValue = items.has(2);
82
+ let hasValue = track(() => items.has(2));
83
83
 
84
84
  <button onClick={() => items.delete(2)}>{'delete'}</button>
85
- <pre>{$hasValue}</pre>
85
+ <pre>{@hasValue}</pre>
86
86
  }
87
87
 
88
88
  render(SetTest);
package/types/index.d.ts CHANGED
@@ -84,4 +84,4 @@ export declare function createRefKey(): symbol;
84
84
 
85
85
  type Tracked<V> = { '#v': V };
86
86
 
87
- export declare function track<V>(value: V | (() => V)): Tracked<V>;
87
+ export declare function track<V>(value?: V | (() => V)): Tracked<V>;
@@ -1,352 +0,0 @@
1
- import { TRACKED_OBJECT } from './constants';
2
- import { old_get_property } from './runtime';
3
-
4
- const array_proto = Array.prototype;
5
-
6
- /**
7
- * @template T
8
- * @param {Array<T>} array
9
- * @param {(previousValue: T, currentValue: T, currentIndex: number, array: Array<T>) => T} callback
10
- * @param {T} initial_value
11
- * @returns {T}
12
- */
13
- export function array_reduce(array, callback, initial_value) {
14
- // @ts-expect-error
15
- var tracked_properties = array[TRACKED_OBJECT];
16
-
17
- if (tracked_properties === undefined || array.reduce !== array_proto.reduce) {
18
- return array.reduce(callback, initial_value);
19
- }
20
-
21
- let accumulator = initial_value;
22
-
23
- for (let i = 0; i < array.length; i++) {
24
- accumulator = callback(accumulator, old_get_property(array, i), i, array);
25
- }
26
-
27
- return accumulator;
28
- }
29
-
30
- /**
31
- * @template T
32
- * @param {Array<T>} array
33
- * @param {string} [separator]
34
- * @returns {string}
35
- */
36
- export function array_join(array, separator) {
37
- // @ts-expect-error
38
- var tracked_properties = array[TRACKED_OBJECT];
39
- if (tracked_properties === undefined || array.join !== array_proto.join) {
40
- return array.join(separator);
41
- }
42
-
43
- let result = '';
44
- for (let i = 0; i < array.length; i++) {
45
- if (i > 0 && separator !== undefined) {
46
- result += separator;
47
- }
48
- result += String(old_get_property(array, i));
49
- }
50
-
51
- return result;
52
- }
53
-
54
- /**
55
- * @template T
56
- * @template U
57
- * @param {Array<T>} array
58
- * @param {(value: T, index: number, array: Array<T>) => U} callback
59
- * @returns {Array<U>}
60
- */
61
- export function array_map(array, callback) {
62
- // @ts-expect-error
63
- var tracked_properties = array[TRACKED_OBJECT];
64
- if (tracked_properties === undefined || array.map !== array_proto.map) {
65
- return array.map(callback);
66
- }
67
-
68
- const result = [];
69
- for (let i = 0; i < array.length; i++) {
70
- if (i in array) {
71
- result[i] = callback(old_get_property(array, i), i, array);
72
- }
73
- }
74
-
75
- return result;
76
- }
77
-
78
- /**
79
- * @template T
80
- * @param {Array<T>} array
81
- * @param {(value: T, index: number, array: Array<T>) => boolean} callback
82
- * @returns {Array<T>}
83
- */
84
- export function array_filter(array, callback) {
85
- // @ts-expect-error
86
- var tracked_properties = array[TRACKED_OBJECT];
87
- if (tracked_properties === undefined || array.filter !== array_proto.filter) {
88
- return array.filter(callback);
89
- }
90
-
91
- const result = [];
92
- for (let i = 0; i < array.length; i++) {
93
- if (i in array) {
94
- const value = old_get_property(array, i);
95
- if (callback(value, i, array)) {
96
- result.push(value);
97
- }
98
- }
99
- }
100
-
101
- return result;
102
- }
103
-
104
- /**
105
- * @template T
106
- * @param {Array<T>} array
107
- * @param {(value: T, index: number, array: Array<T>) => boolean} callback
108
- * @returns {void}
109
- */
110
- export function array_forEach(array, callback) {
111
- // @ts-expect-error
112
- var tracked_properties = array[TRACKED_OBJECT];
113
- if (tracked_properties === undefined || array.forEach !== array_proto.forEach) {
114
- return array.forEach(callback);
115
- }
116
-
117
- for (let i = 0; i < array.length; i++) {
118
- if (i in array) {
119
- callback(old_get_property(array, i), i, array);
120
- }
121
- }
122
- }
123
-
124
- /**
125
- * @template T
126
- * @param {Array<T>} array
127
- * @param {T} value
128
- * @returns {boolean}
129
- */
130
- export function array_includes(array, value) {
131
- // @ts-expect-error
132
- var tracked_properties = array[TRACKED_OBJECT];
133
- if (tracked_properties === undefined || array.includes !== array_proto.includes) {
134
- return array.includes(value);
135
- }
136
-
137
- for (let i = 0; i < array.length; i++) {
138
- if (i in array && old_get_property(array, i) === value) {
139
- return true;
140
- }
141
- }
142
-
143
- return false;
144
- }
145
-
146
- /**
147
- * @template T
148
- * @param {Array<T>} array
149
- * @param {T} value
150
- * @returns {number}
151
- */
152
- export function array_indexOf(array, value) {
153
- // @ts-expect-error
154
- var tracked_properties = array[TRACKED_OBJECT];
155
- if (tracked_properties === undefined || array.indexOf !== array_proto.indexOf) {
156
- return array.indexOf(value);
157
- }
158
-
159
- for (let i = 0; i < array.length; i++) {
160
- if (i in array && old_get_property(array, i) === value) {
161
- return i;
162
- }
163
- }
164
-
165
- return -1;
166
- }
167
-
168
- /**
169
- * @template T
170
- * @param {Array<T>} array
171
- * @param {T} value
172
- * @returns {number}
173
- */
174
- export function array_lastIndexOf(array, value) {
175
- // @ts-expect-error
176
- var tracked_properties = array[TRACKED_OBJECT];
177
- if (tracked_properties === undefined || array.lastIndexOf !== array_proto.lastIndexOf) {
178
- return array.lastIndexOf(value);
179
- }
180
-
181
- for (let i = array.length - 1; i >= 0; i--) {
182
- if (i in array && old_get_property(array, i) === value) {
183
- return i;
184
- }
185
- }
186
-
187
- return -1;
188
- }
189
-
190
- /**
191
- * @template T
192
- * @param {Array<T>} array
193
- * @param {(value: T, index: number, array: Array<T>) => boolean} callback
194
- * @returns {boolean}
195
- */
196
- export function array_every(array, callback) {
197
- // @ts-expect-error
198
- var tracked_properties = array[TRACKED_OBJECT];
199
- if (tracked_properties === undefined || array.every !== array_proto.every) {
200
- return array.every(callback);
201
- }
202
-
203
- for (let i = 0; i < array.length; i++) {
204
- if (i in array && !callback(old_get_property(array, i), i, array)) {
205
- return false;
206
- }
207
- }
208
-
209
- return true;
210
- }
211
-
212
- /**
213
- * @template T
214
- * @param {Array<T>} array
215
- * @param {(value: T, index: number, array: Array<T>) => boolean} callback
216
- * @returns {boolean}
217
- */
218
- export function array_some(array, callback) {
219
- // @ts-expect-error
220
- var tracked_properties = array[TRACKED_OBJECT];
221
- if (tracked_properties === undefined || array.some !== array_proto.some) {
222
- return array.some(callback);
223
- }
224
-
225
- for (let i = 0; i < array.length; i++) {
226
- if (i in array && callback(old_get_property(array, i), i, array)) {
227
- return true;
228
- }
229
- }
230
-
231
- return false;
232
- }
233
-
234
- /**
235
- * @template T
236
- * @param {Array<T>} array
237
- * @returns {string}
238
- */
239
- export function array_toString(array) {
240
- // @ts-expect-error
241
- var tracked_properties = array[TRACKED_OBJECT];
242
- if (tracked_properties === undefined || array.toString !== array_proto.toString) {
243
- return array.toString();
244
- }
245
-
246
- let result = '';
247
- for (let i = 0; i < array.length; i++) {
248
- if (i > 0) {
249
- result += ',';
250
- }
251
- if (i in array) {
252
- result += String(old_get_property(array, i));
253
- }
254
- }
255
-
256
- return result;
257
- }
258
-
259
- /**
260
- * @template T
261
- * @param {Array<T>} array
262
- * @param {((a: T, b: T) => number) | undefined} compare_fn
263
- * @returns {Array<T>}
264
- */
265
- export function array_toSorted(array, compare_fn) {
266
- // @ts-expect-error
267
- var tracked_properties = array[TRACKED_OBJECT];
268
- if (tracked_properties === undefined || array.toSorted !== array_proto.toSorted) {
269
- return array.toSorted(compare_fn);
270
- }
271
-
272
- const result = [];
273
- for (let i = 0; i < array.length; i++) {
274
- if (i in array) {
275
- result.push(old_get_property(array, i));
276
- }
277
- }
278
-
279
- return result.sort(compare_fn);
280
- }
281
-
282
- /**
283
- * @template T
284
- * @param {Array<T>} array
285
- * @param {number} start
286
- * @param {number} delete_count
287
- * @param {...T} items
288
- * @returns {Array<T>}
289
- */
290
- export function array_toSpliced(array, start, delete_count, ...items) {
291
- // @ts-expect-error
292
- var tracked_properties = array[TRACKED_OBJECT];
293
- if (tracked_properties === undefined || array.toSpliced !== array_proto.toSpliced) {
294
- return array.toSpliced(start, delete_count, ...items);
295
- }
296
-
297
- const result = [];
298
- for (let i = 0; i < array.length; i++) {
299
- if (i in array) {
300
- result.push(old_get_property(array, i));
301
- }
302
- }
303
-
304
- result.splice(start, delete_count, ...items);
305
-
306
- return result;
307
- }
308
-
309
- /**
310
- * @template T
311
- * @param {Array<T>} array
312
- * @returns {IterableIterator<T>}
313
- */
314
- export function array_values(array) {
315
- // @ts-expect-error
316
- var tracked_properties = array[TRACKED_OBJECT];
317
- if (tracked_properties === undefined || array.values !== array_proto.values) {
318
- return array.values();
319
- }
320
-
321
- const result = [];
322
- for (let i = 0; i < array.length; i++) {
323
- if (i in array) {
324
- result.push(old_get_property(array, i));
325
- }
326
- }
327
-
328
- return result[Symbol.iterator]();
329
- }
330
-
331
- /**
332
- * @template T
333
- * @param {Array<T>} array
334
- * @returns {IterableIterator<[number, T]>}
335
- */
336
- export function array_entries(array) {
337
- // @ts-expect-error
338
- var tracked_properties = array[TRACKED_OBJECT];
339
- if (tracked_properties === undefined || array.entries !== array_proto.entries) {
340
- return array.entries();
341
- }
342
-
343
- /** @type {Array<[number, T]>} */
344
- const result = [];
345
- for (let i = 0; i < array.length; i++) {
346
- if (i in array) {
347
- result.push([i, old_get_property(array, i)]);
348
- }
349
- }
350
-
351
- return result[Symbol.iterator]();
352
- }