ripple 0.2.51 → 0.2.53

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
@@ -3,7 +3,7 @@
3
3
  "description": "Ripple is an elegant TypeScript UI framework",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.2.51",
6
+ "version": "0.2.53",
7
7
  "type": "module",
8
8
  "module": "src/runtime/index.js",
9
9
  "main": "src/runtime/index.js",
@@ -823,7 +823,7 @@ const visitors = {
823
823
  b.call(
824
824
  node.id,
825
825
  id,
826
- b.call('$.tracked_spread_object', b.thunk(b.object(props))),
826
+ b.call('$.tracked_spread_object', b.thunk(b.object(props)), b.id('__block')),
827
827
  b.id('$.active_block'),
828
828
  ),
829
829
  ),
@@ -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
- var obj = fn();
786
+ export function tracked_spread_object(fn, block) {
787
+ let computed = derived(fn, block);
788
788
 
789
- define_property(obj, SPREAD_OBJECT, {
790
- value: fn,
791
- enumerable: false,
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
  }
@@ -1267,6 +1263,9 @@ export function exclude_from_object(obj, keys) {
1267
1263
  return obj;
1268
1264
  }
1269
1265
 
1266
+ /**
1267
+ * @param {any} v
1268
+ */
1270
1269
  export async function maybe_tracked(v) {
1271
1270
  var restore = capture();
1272
1271
  let value;
@@ -1275,7 +1274,9 @@ export async function maybe_tracked(v) {
1275
1274
  if ((v.f & DERIVED) !== 0) {
1276
1275
  value = await async_computed(v.fn, v.b);
1277
1276
  } else {
1278
- value = await get_tracked(v);
1277
+ value = await async_computed(async () => {
1278
+ return await get_tracked(v);
1279
+ }, /** @type {Block} */ (active_block));
1279
1280
  }
1280
1281
  } else {
1281
1282
  value = await v;
@@ -1547,7 +1547,7 @@ describe('RippleArray', () => {
1547
1547
  }
1548
1548
 
1549
1549
  component ArrayTest() {
1550
- //const items = await RippleArray.fromAsync([6]);
1550
+ const items = await RippleArray.fromAsync([6]);
1551
1551
 
1552
1552
  <pre>{items ? JSON.stringify(items) : 'Loading...'}</pre>
1553
1553
  <pre>{items ? items.$length : ''}</pre>
@@ -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
  });