ripple 0.2.112 → 0.2.114
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 +1 -0
- package/src/compiler/phases/3-transform/client/index.js +18 -13
- package/src/compiler/phases/3-transform/segments.js +1 -1
- package/src/runtime/index-client.js +185 -5
- package/src/runtime/internal/client/runtime.js +4 -4
- package/src/runtime/internal/client/types.d.ts +2 -2
- package/src/utils/builders.js +274 -262
- package/tests/client/input-value.test.ripple +123 -0
- package/types/index.d.ts +12 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { mount, flushSync, track, effect } from 'ripple';
|
|
3
|
+
import { bindValue, bindChecked } from 'ripple';
|
|
4
|
+
|
|
5
|
+
describe('use value()', () => {
|
|
6
|
+
let container;
|
|
7
|
+
|
|
8
|
+
function render(component) {
|
|
9
|
+
mount(component, {
|
|
10
|
+
target: container,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
container = document.createElement('div');
|
|
16
|
+
document.body.appendChild(container);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
document.body.removeChild(container);
|
|
21
|
+
container = null;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should update value on input', () => {
|
|
25
|
+
const logs = [];
|
|
26
|
+
|
|
27
|
+
component App() {
|
|
28
|
+
const text = track('');
|
|
29
|
+
|
|
30
|
+
effect(() => {
|
|
31
|
+
logs.push('text changed', @text);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
<input type="text" {ref bindValue(text)} />
|
|
35
|
+
}
|
|
36
|
+
render(App);
|
|
37
|
+
flushSync();
|
|
38
|
+
|
|
39
|
+
const input = container.querySelector('input');
|
|
40
|
+
input.value = 'Hello';
|
|
41
|
+
input.dispatchEvent(new Event('input'));
|
|
42
|
+
flushSync();
|
|
43
|
+
expect(input.value).toBe('Hello');
|
|
44
|
+
expect(logs).toEqual(['text changed', '', 'text changed', 'Hello']);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should update value on input with a predefined value', () => {
|
|
48
|
+
const logs = [];
|
|
49
|
+
|
|
50
|
+
component App() {
|
|
51
|
+
const text = track('foo');
|
|
52
|
+
|
|
53
|
+
effect(() => {
|
|
54
|
+
logs.push('text changed', @text);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
<input type="text" {ref bindValue(text)} />
|
|
58
|
+
}
|
|
59
|
+
render(App);
|
|
60
|
+
flushSync();
|
|
61
|
+
|
|
62
|
+
expect(container.querySelector('input').value).toBe('foo');
|
|
63
|
+
const input = container.querySelector('input');
|
|
64
|
+
input.value = 'Hello';
|
|
65
|
+
input.dispatchEvent(new Event('input'));
|
|
66
|
+
flushSync();
|
|
67
|
+
expect(input.value).toBe('Hello');
|
|
68
|
+
expect(logs).toEqual(['text changed', 'foo', 'text changed', 'Hello']);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should update checked on input', () => {
|
|
72
|
+
const logs = [];
|
|
73
|
+
|
|
74
|
+
component App() {
|
|
75
|
+
const value = track(false);
|
|
76
|
+
|
|
77
|
+
effect(() => {
|
|
78
|
+
logs.push('checked changed', @value);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
<input type="checkbox" {ref bindChecked(value)} />
|
|
82
|
+
}
|
|
83
|
+
render(App);
|
|
84
|
+
flushSync();
|
|
85
|
+
|
|
86
|
+
const input = container.querySelector('input');
|
|
87
|
+
input.checked = true;
|
|
88
|
+
input.dispatchEvent(new Event('change'));
|
|
89
|
+
flushSync();
|
|
90
|
+
|
|
91
|
+
expect(input.checked).toBe(true);
|
|
92
|
+
expect(logs).toEqual(['checked changed', false, 'checked changed', true]);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should update select value on change', () => {
|
|
96
|
+
const logs = [];
|
|
97
|
+
|
|
98
|
+
component App() {
|
|
99
|
+
const select = track('2');
|
|
100
|
+
|
|
101
|
+
effect(() => {
|
|
102
|
+
logs.push('select changed', @select);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
<select {ref bindValue(select)}>
|
|
106
|
+
<option value="1">{"One"}</option>
|
|
107
|
+
<option value="2">{"Two"}</option>
|
|
108
|
+
<option value="3">{"Three"}</option>
|
|
109
|
+
</select>
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
render(App);
|
|
113
|
+
flushSync();
|
|
114
|
+
|
|
115
|
+
const select = container.querySelector('select');
|
|
116
|
+
select.value = '3';
|
|
117
|
+
select.dispatchEvent(new Event('change'));
|
|
118
|
+
flushSync();
|
|
119
|
+
|
|
120
|
+
expect(select.value).toBe('3');
|
|
121
|
+
expect(logs).toEqual(['select changed', '2', 'select changed', '3']);
|
|
122
|
+
});
|
|
123
|
+
});
|
package/types/index.d.ts
CHANGED
|
@@ -200,3 +200,15 @@ export declare const MediaQuery: {
|
|
|
200
200
|
};
|
|
201
201
|
|
|
202
202
|
export function Portal<V = HTMLElement>({ target, children: Component }: { target: V, children?: Component }): void;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @param {Tracked<V>} tracked
|
|
206
|
+
* @returns {(node: HTMLInputElement | HTMLSelectElement) => void}
|
|
207
|
+
*/
|
|
208
|
+
export declare function bindValue<V>(tracked: Tracked<V>): (node: HTMLInputElement | HTMLSelectElement) => void;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @param {Tracked<V>} tracked
|
|
212
|
+
* @returns {(node: HTMLInputElement) => void}
|
|
213
|
+
*/
|
|
214
|
+
export declare function bindChecked<V>(tracked: Tracked<V>): (node: HTMLInputElement) => void;
|