ripple 0.2.84 → 0.2.86

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.84",
6
+ "version": "0.2.86",
7
7
  "type": "module",
8
8
  "module": "src/runtime/index-client.js",
9
9
  "main": "src/runtime/index-client.js",
@@ -379,7 +379,6 @@ export function is_component_level_function(context) {
379
379
  }
380
380
 
381
381
  export function is_ripple_track_call(callee, context) {
382
- <<<<<<< Updated upstream
383
382
  return (
384
383
  (callee.type === 'Identifier' && (callee.name === 'track' || callee.name === 'trackSplit')) ||
385
384
  (callee.type === 'MemberExpression' &&
@@ -389,17 +388,6 @@ export function is_ripple_track_call(callee, context) {
389
388
  !callee.computed &&
390
389
  is_ripple_import(callee, context))
391
390
  );
392
- =======
393
- return (
394
- (callee.type === 'Identifier' && callee.name === 'track') ||
395
- (callee.type === 'MemberExpression' &&
396
- callee.object.type === 'Identifier' &&
397
- callee.property.type === 'Identifier' &&
398
- callee.property.name === 'track' &&
399
- !callee.computed &&
400
- is_ripple_import(callee, context))
401
- );
402
- >>>>>>> Stashed changes
403
391
  }
404
392
 
405
393
  export function is_inside_call_expression(context) {
@@ -1,5 +1,4 @@
1
1
  /** @import { Block, Component, Dependency, Derived, Tracked } from '#client' */
2
- /** @import { TrackOptions } from '#public' */
3
2
 
4
3
  import {
5
4
  destroy_block,
@@ -289,8 +288,8 @@ export function derived(fn, block, get, set) {
289
288
 
290
289
  /**
291
290
  * @param {any} v
292
- * @param {Function | undefined} get
293
- * @param {Function | undefined} set
291
+ * @param {(value: any) => any | undefined} get
292
+ * @param {(next: any, prev: any) => any | undefined} set
294
293
  * @param {Block} b
295
294
  * @returns {Tracked | Derived}
296
295
  */
@@ -800,7 +799,7 @@ export function set(tracked, value, block) {
800
799
 
801
800
  var set = tracked.a.set;
802
801
  if (set) {
803
- value = set(value);
802
+ value = set(value, old_value);
804
803
  }
805
804
 
806
805
  tracked.v = value;
@@ -1498,6 +1498,27 @@ describe('basic client', () => {
1498
1498
  expect(countDiv.textContent).toBe('3');
1499
1499
  });
1500
1500
 
1501
+ it('passes in next and prev to track set function', () => {
1502
+ let logs = [];
1503
+
1504
+ component App() {
1505
+ let count = track(0, v => v, (next, prev) => {
1506
+ logs.push(prev, next);
1507
+ return next;
1508
+ });
1509
+
1510
+ <button onClick={() => { @count++ }}>{'Increment'}</button>
1511
+ }
1512
+
1513
+ render(App);
1514
+
1515
+ const button = container.querySelector('button');
1516
+ button.click();
1517
+ flushSync();
1518
+
1519
+ expect(logs).toEqual([0, 1]);
1520
+ });
1521
+
1501
1522
  it('works as a reactive TrackedArray when constructed using # syntactic sugar', () => {
1502
1523
  component App() {
1503
1524
  const array = #[1, 2, 3];
package/types/index.d.ts CHANGED
@@ -86,7 +86,7 @@ type RestKeys<T, K extends readonly (keyof T)[]> = Expand<Omit<T, K[number]>>;
86
86
  type SplitResult<T extends Props, K extends readonly (keyof T)[]> =
87
87
  [...PickKeys<T, K>, Tracked<RestKeys<T, K>>];
88
88
 
89
- export declare function track<V>(value?: V | (() => V), get?: (v: V) => V, set?: (v: V) => V): Tracked<V>;
89
+ export declare function track<V>(value?: V | (() => V), get?: (v: V) => V, set?: (next: V, prev: V) => V): Tracked<V>;
90
90
 
91
91
  export declare function trackSplit<V extends Props, const K extends readonly (keyof V)[]>(
92
92
  value: V,