ripple 0.2.85 → 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
|
@@ -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 {
|
|
293
|
-
* @param {
|
|
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?: (
|
|
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,
|