ripple 0.2.80 → 0.2.82
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 +1 -1
- package/src/compiler/phases/1-parse/index.js +0 -34
- package/src/compiler/phases/2-analyze/index.js +0 -12
- package/src/compiler/phases/3-transform/client/index.js +1 -61
- package/src/compiler/phases/3-transform/server/index.js +37 -1
- package/src/compiler/utils.js +16 -0
- package/src/runtime/internal/client/runtime.js +739 -711
- package/src/runtime/internal/client/types.d.ts +2 -0
- package/tests/client/basic.test.ripple +7 -2
- package/types/index.d.ts +2 -2
- package/tests/client/accessors-props.test.ripple +0 -146
|
@@ -18,6 +18,7 @@ export type Dependency = {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export type Tracked = {
|
|
21
|
+
a: { get?: Function, set?: Function };
|
|
21
22
|
b: Block;
|
|
22
23
|
c: number;
|
|
23
24
|
f: number;
|
|
@@ -25,6 +26,7 @@ export type Tracked = {
|
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
export type Derived = {
|
|
29
|
+
a: { get?: Function, set?: Function };
|
|
28
30
|
b: Block;
|
|
29
31
|
blocks: null | Block[];
|
|
30
32
|
c: number;
|
|
@@ -1276,7 +1276,12 @@ describe('basic client', () => {
|
|
|
1276
1276
|
let logs = [];
|
|
1277
1277
|
|
|
1278
1278
|
component App() {
|
|
1279
|
-
let count = track(0
|
|
1279
|
+
let count = track(0, {
|
|
1280
|
+
set(v) {
|
|
1281
|
+
logs.push('inside setter');
|
|
1282
|
+
return v;
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1280
1285
|
let name = track('Click Me');
|
|
1281
1286
|
|
|
1282
1287
|
function buttonRef(el) {
|
|
@@ -1289,7 +1294,7 @@ describe('basic client', () => {
|
|
|
1289
1294
|
<Child
|
|
1290
1295
|
class="my-button"
|
|
1291
1296
|
onClick={() => @name === 'Click Me' ? @name = 'Clicked' : @name = 'Click Me'}
|
|
1292
|
-
|
|
1297
|
+
{count}
|
|
1293
1298
|
{ref buttonRef}
|
|
1294
1299
|
>{@name}</Child>;
|
|
1295
1300
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -89,13 +89,13 @@ type RestKeys<T, K extends readonly (keyof T)[]> = Expand<Omit<T, K[number]>>;
|
|
|
89
89
|
type SplitResult<T extends Props, K extends readonly (keyof T)[]> =
|
|
90
90
|
[...PickKeys<T, K>, UnwrapTracked<RestKeys<T, K>>];
|
|
91
91
|
|
|
92
|
-
type TrackOptions = { split?: readonly (string | number | symbol)[] };
|
|
92
|
+
type TrackOptions<T> = { split?: readonly (string | number | symbol)[], get?: (v: T) => T, set?: (v: T) => T };
|
|
93
93
|
|
|
94
94
|
export declare function track<V>(value?: V | (() => V)): Tracked<V>;
|
|
95
95
|
|
|
96
96
|
export declare function track<V extends Props, const K extends readonly (keyof V)[]>(
|
|
97
97
|
value: V,
|
|
98
|
-
options: TrackOptions
|
|
98
|
+
options: TrackOptions<V>
|
|
99
99
|
): SplitResult<V, K>;
|
|
100
100
|
|
|
101
101
|
export function on<Type extends keyof WindowEventMap>(
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { mount, flushSync, effect, track } from 'ripple';
|
|
3
|
-
|
|
4
|
-
describe('prop accessors', () => {
|
|
5
|
-
let container;
|
|
6
|
-
|
|
7
|
-
function render(component) {
|
|
8
|
-
mount(component, {
|
|
9
|
-
target: container
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
container = document.createElement('div');
|
|
15
|
-
document.body.appendChild(container);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
document.body.removeChild(container);
|
|
20
|
-
container = null;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should render a basic prop accessor on a composite component', () => {
|
|
24
|
-
const logs = [];
|
|
25
|
-
|
|
26
|
-
component Child(props) {
|
|
27
|
-
effect(() => {
|
|
28
|
-
logs.push('App effect', props.@foo);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
<button onClick={() => props.@foo++}>{"Increment foo"}</button>
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
component App(props) {
|
|
35
|
-
let foo = track(0);
|
|
36
|
-
|
|
37
|
-
<Child {foo} />
|
|
38
|
-
|
|
39
|
-
<div>{"parent foo: " + @foo}</div>
|
|
40
|
-
|
|
41
|
-
<button onClick={() => { @foo++; }}>{"Increment parent foo"}</button>
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
render(App);
|
|
45
|
-
flushSync();
|
|
46
|
-
|
|
47
|
-
expect(container.querySelectorAll('div')[0].textContent).toBe('parent foo: 0');
|
|
48
|
-
expect(logs).toEqual(['App effect', 0]);
|
|
49
|
-
|
|
50
|
-
const [button, button2] = container.querySelectorAll('button');
|
|
51
|
-
|
|
52
|
-
button.click();
|
|
53
|
-
flushSync();
|
|
54
|
-
|
|
55
|
-
expect(container.querySelectorAll('div')[0].textContent).toBe('parent foo: 1');
|
|
56
|
-
expect(logs).toEqual(['App effect', 0, 'App effect', 1]);
|
|
57
|
-
|
|
58
|
-
button2.click();
|
|
59
|
-
flushSync();
|
|
60
|
-
|
|
61
|
-
expect(container.querySelectorAll('div')[0].textContent).toBe('parent foo: 2');
|
|
62
|
-
expect(logs).toEqual(['App effect', 0, 'App effect', 1, 'App effect', 2]);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// Note: Disabled this test for further investigation.
|
|
66
|
-
it.skip('should render a basic prop accessor on a composite component #2', () => {
|
|
67
|
-
const logs = [];
|
|
68
|
-
|
|
69
|
-
component Child({ foo }) {
|
|
70
|
-
effect(() => {
|
|
71
|
-
logs.push('App effect', props.foo);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
<button onClick={() => props.foo++}>{"Increment foo"}</button>
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
component App() {
|
|
78
|
-
let foo = track(0);
|
|
79
|
-
|
|
80
|
-
<Child foo:={() => {
|
|
81
|
-
return @foo;
|
|
82
|
-
}, v => {
|
|
83
|
-
// do not update parent
|
|
84
|
-
}} />
|
|
85
|
-
|
|
86
|
-
<div>{"parent foo: " + @foo}</div>
|
|
87
|
-
|
|
88
|
-
<button onClick={() => { foo++ }}>{"Increment parent foo"}</button>
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
render(App);
|
|
92
|
-
flushSync();
|
|
93
|
-
|
|
94
|
-
expect(container.querySelectorAll('div')[0].textContent).toBe('parent foo: 0');
|
|
95
|
-
expect(logs).toEqual(['App effect', 0]);
|
|
96
|
-
|
|
97
|
-
const [button, button2] = container.querySelectorAll('button');
|
|
98
|
-
|
|
99
|
-
button.click();
|
|
100
|
-
flushSync();
|
|
101
|
-
|
|
102
|
-
expect(container.querySelectorAll('div')[0].textContent).toBe('parent foo: 0');
|
|
103
|
-
expect(logs).toEqual(['App effect', 0]);
|
|
104
|
-
|
|
105
|
-
button2.click();
|
|
106
|
-
flushSync();
|
|
107
|
-
|
|
108
|
-
expect(container.querySelectorAll('div')[0].textContent).toBe('parent foo: 1');
|
|
109
|
-
expect(logs).toEqual(['App effect', 0, 'App effect', 1]);
|
|
110
|
-
|
|
111
|
-
button2.click();
|
|
112
|
-
flushSync();
|
|
113
|
-
|
|
114
|
-
expect(container.querySelectorAll('div')[0].textContent).toBe('parent foo: 2');
|
|
115
|
-
expect(logs).toEqual(['App effect', 0, 'App effect', 1, 'App effect', 2]);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('handles a simple getter prop accessor with no setter', () =>{
|
|
119
|
-
component Parent() {
|
|
120
|
-
let value = track(123);
|
|
121
|
-
|
|
122
|
-
<Child value:={() => @value} />
|
|
123
|
-
|
|
124
|
-
<button onClick={() => { @value++ }}>{"Increment value"}</button>
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
component Child({ value }) {
|
|
128
|
-
<div>{value}</div>
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
render(Parent);
|
|
132
|
-
|
|
133
|
-
expect(container.querySelector('div').textContent).toBe('123');
|
|
134
|
-
|
|
135
|
-
const button = container.querySelector('button');
|
|
136
|
-
button.click();
|
|
137
|
-
flushSync();
|
|
138
|
-
|
|
139
|
-
expect(container.querySelector('div').textContent).toBe('124');
|
|
140
|
-
|
|
141
|
-
button.click();
|
|
142
|
-
flushSync();
|
|
143
|
-
|
|
144
|
-
expect(container.querySelector('div').textContent).toBe('125');
|
|
145
|
-
});
|
|
146
|
-
});
|