ripple 0.2.51 → 0.2.52
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/package.json
CHANGED
|
@@ -21,7 +21,6 @@ export var LOGIC_BLOCK = FOR_BLOCK | IF_BLOCK | TRY_BLOCK;
|
|
|
21
21
|
export var UNINITIALIZED = Symbol();
|
|
22
22
|
/** @type {unique symbol} */
|
|
23
23
|
export const TRACKED_OBJECT = Symbol();
|
|
24
|
-
export var SPREAD_OBJECT = Symbol();
|
|
25
24
|
export var COMPUTED_PROPERTY = Symbol();
|
|
26
25
|
export var REF_PROP = 'ref';
|
|
27
26
|
/** @type {unique symbol} */
|
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
EFFECT_BLOCK,
|
|
21
21
|
PAUSED,
|
|
22
22
|
ROOT_BLOCK,
|
|
23
|
-
SPREAD_OBJECT,
|
|
24
23
|
TRACKED,
|
|
25
24
|
TRACKED_OBJECT,
|
|
26
25
|
TRY_BLOCK,
|
|
@@ -781,17 +780,18 @@ export function flush_sync(fn) {
|
|
|
781
780
|
|
|
782
781
|
/**
|
|
783
782
|
* @param {() => Object} fn
|
|
783
|
+
* @param {Block} block
|
|
784
784
|
* @returns {Object}
|
|
785
785
|
*/
|
|
786
|
-
export function tracked_spread_object(fn) {
|
|
787
|
-
|
|
786
|
+
export function tracked_spread_object(fn, block) {
|
|
787
|
+
let computed = derived(fn, block);
|
|
788
788
|
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
789
|
+
return new Proxy({}, {
|
|
790
|
+
get(target, property) {
|
|
791
|
+
const obj = get_derived(computed);
|
|
792
|
+
return obj[property];
|
|
793
|
+
}
|
|
792
794
|
});
|
|
793
|
-
|
|
794
|
-
return obj;
|
|
795
795
|
}
|
|
796
796
|
|
|
797
797
|
/**
|
|
@@ -918,10 +918,6 @@ export function old_get_property(obj, property, chain = false) {
|
|
|
918
918
|
if (obj[property] !== value) {
|
|
919
919
|
obj[property] = value;
|
|
920
920
|
}
|
|
921
|
-
} else if (SPREAD_OBJECT in obj) {
|
|
922
|
-
var spread_fn = obj[SPREAD_OBJECT];
|
|
923
|
-
var properties = spread_fn();
|
|
924
|
-
return old_get_property(properties, property, chain);
|
|
925
921
|
} else if (is_ripple_array(obj)) {
|
|
926
922
|
obj.$length;
|
|
927
923
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { mount, flushSync, track, RippleArray } from 'ripple';
|
|
2
|
+
import { mount, flushSync, track, RippleArray, effect } from 'ripple';
|
|
3
3
|
|
|
4
4
|
describe('composite components', () => {
|
|
5
5
|
let container;
|
|
@@ -295,4 +295,45 @@ describe('composite components', () => {
|
|
|
295
295
|
|
|
296
296
|
render(ArrayTest);
|
|
297
297
|
});
|
|
298
|
+
|
|
299
|
+
it('handles spreading of props', () => {
|
|
300
|
+
let logs = [];
|
|
301
|
+
|
|
302
|
+
component App() {
|
|
303
|
+
const a = track(1);
|
|
304
|
+
const b = track(2);
|
|
305
|
+
const c = track(3);
|
|
306
|
+
|
|
307
|
+
const obj = track(() => ({
|
|
308
|
+
@a,
|
|
309
|
+
@b,
|
|
310
|
+
@c,
|
|
311
|
+
}));
|
|
312
|
+
|
|
313
|
+
<Child {...@obj} />
|
|
314
|
+
|
|
315
|
+
<button onClick={() => { @a++; @b++; @c++; }}>{"Increment all"}</button>
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
component Child({ a, b, c }) {
|
|
319
|
+
effect(() => {
|
|
320
|
+
logs.push(`Child effect: ${a}, ${b}, ${c}`);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
<div>{a + ' ' + b + ' ' + c}</div>
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
render(App);
|
|
327
|
+
flushSync();
|
|
328
|
+
|
|
329
|
+
expect(container.querySelector('div').textContent).toBe('1 2 3');
|
|
330
|
+
expect(logs).toEqual(['Child effect: 1, 2, 3']);
|
|
331
|
+
|
|
332
|
+
const button = container.querySelector('button');
|
|
333
|
+
button.click();
|
|
334
|
+
flushSync();
|
|
335
|
+
|
|
336
|
+
expect(container.querySelector('div').textContent).toBe('2 3 4');
|
|
337
|
+
expect(logs).toEqual(['Child effect: 1, 2, 3', 'Child effect: 2, 3, 4']);
|
|
338
|
+
});
|
|
298
339
|
});
|