ripple 0.2.14 → 0.2.15
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/3-transform/index.js +1 -1
- package/src/runtime/index.js +0 -1
- package/src/runtime/internal/client/blocks.js +1 -9
- package/src/runtime/internal/client/runtime.js +1 -19
- package/src/runtime/internal/client/types.d.ts +0 -4
- package/tests/context.test.ripple +3 -3
- package/types/index.d.ts +0 -6
- package/tests/ref.test.ripple +0 -54
package/package.json
CHANGED
|
@@ -1403,7 +1403,7 @@ function transform_children(children, { visit, state, root }) {
|
|
|
1403
1403
|
|
|
1404
1404
|
if (child.type === 'Text' && prev_child?.type === 'Text') {
|
|
1405
1405
|
if (child.expression.type === 'Literal' && prev_child.expression.type === 'Literal') {
|
|
1406
|
-
prev_child.expression.value
|
|
1406
|
+
prev_child.expression = b.literal(prev_child.expression.value + child.expression.value);
|
|
1407
1407
|
} else {
|
|
1408
1408
|
prev_child.expression = b.binary('+', prev_child.expression, child.expression);
|
|
1409
1409
|
}
|
package/src/runtime/index.js
CHANGED
|
@@ -96,7 +96,6 @@ export function async(fn) {
|
|
|
96
96
|
export function use(element, get_fn) {
|
|
97
97
|
var use_obj = undefined;
|
|
98
98
|
var e;
|
|
99
|
-
var current_block = active_block;
|
|
100
99
|
|
|
101
100
|
return block(RENDER_BLOCK, () => {
|
|
102
101
|
if (use_obj !== (use_obj = get_fn())) {
|
|
@@ -108,14 +107,7 @@ export function use(element, get_fn) {
|
|
|
108
107
|
if (use_obj) {
|
|
109
108
|
e = branch(() => {
|
|
110
109
|
effect(() => {
|
|
111
|
-
|
|
112
|
-
return use_obj(element);
|
|
113
|
-
} else {
|
|
114
|
-
set_property(use_obj, '$current', element, current_block);
|
|
115
|
-
return () => {
|
|
116
|
-
set_property(use_obj, '$current', null, current_block);
|
|
117
|
-
};
|
|
118
|
-
}
|
|
110
|
+
return use_obj(element);
|
|
119
111
|
});
|
|
120
112
|
});
|
|
121
113
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @import { Block, Component, Dependency, Computed, Tracked
|
|
1
|
+
/** @import { Block, Component, Dependency, Computed, Tracked } from '#client' */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
destroy_block,
|
|
@@ -1053,21 +1053,3 @@ export function pop_component() {
|
|
|
1053
1053
|
export function use_prop() {
|
|
1054
1054
|
return Symbol(USE_PROP);
|
|
1055
1055
|
}
|
|
1056
|
-
|
|
1057
|
-
/**
|
|
1058
|
-
* @template T
|
|
1059
|
-
* @param {T} value
|
|
1060
|
-
* @returns {Ref<T>}
|
|
1061
|
-
*/
|
|
1062
|
-
export function ref(value) {
|
|
1063
|
-
var block = active_block || active_scope;
|
|
1064
|
-
if (!block) {
|
|
1065
|
-
throw new Error('ref() must be called within a component or reactive context');
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
// Create a tracked object with a $current property
|
|
1069
|
-
var ref_obj = { $current: value };
|
|
1070
|
-
|
|
1071
|
-
// Make the $current property reactive
|
|
1072
|
-
return tracked_object(ref_obj, ['$current'], block);
|
|
1073
|
-
}
|
|
@@ -24,13 +24,13 @@ describe('context', () => {
|
|
|
24
24
|
const MyContext = createContext(null);
|
|
25
25
|
|
|
26
26
|
component Child() {
|
|
27
|
-
const value = MyContext.get(
|
|
27
|
+
const value = MyContext.get();
|
|
28
28
|
|
|
29
29
|
<div>{value}</div>
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
component TestContext() {
|
|
33
|
-
const value = MyContext.get(
|
|
33
|
+
const value = MyContext.get();
|
|
34
34
|
|
|
35
35
|
console.log(value);
|
|
36
36
|
|
|
@@ -43,4 +43,4 @@ describe('context', () => {
|
|
|
43
43
|
|
|
44
44
|
expect(container.querySelector('div').textContent).toBe('Hello from context!');
|
|
45
45
|
});
|
|
46
|
-
});
|
|
46
|
+
});
|
package/types/index.d.ts
CHANGED
|
@@ -11,12 +11,6 @@ export declare function flushSync<T>(fn: () => T): T;
|
|
|
11
11
|
|
|
12
12
|
export declare function effect(fn: (() => void) | (() => () => void)): void;
|
|
13
13
|
|
|
14
|
-
export interface Ref<T> {
|
|
15
|
-
$current: T;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export declare function ref<T>(value: T): Ref<T>;
|
|
19
|
-
|
|
20
14
|
export declare class RippleArray<T> extends Array<T> {
|
|
21
15
|
static from<T>(arrayLike: ArrayLike<T>): RippleArray<T>;
|
|
22
16
|
static from<T, U>(
|
package/tests/ref.test.ripple
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { mount, flushSync, ref } from 'ripple';
|
|
4
|
-
|
|
5
|
-
describe('ref()', () => {
|
|
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
|
-
});
|
|
22
|
-
|
|
23
|
-
it('creates a reactive ref with initial value', () => {
|
|
24
|
-
component TestRef() {
|
|
25
|
-
let $count = 5;
|
|
26
|
-
|
|
27
|
-
<div><span id='count'>{$count}</span></div>
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
render(TestRef);
|
|
31
|
-
|
|
32
|
-
expect(container.querySelector('#count').textContent).toBe('5');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('updates when ref value changes', () => {
|
|
36
|
-
component TestRef() {
|
|
37
|
-
let $count = 0;
|
|
38
|
-
|
|
39
|
-
<div>
|
|
40
|
-
<span id='count'>{$count}</span>
|
|
41
|
-
<button id='btn' onClick={() => $count++}>{'Increment'}</button>
|
|
42
|
-
</div>
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
render(TestRef);
|
|
46
|
-
|
|
47
|
-
expect(container.querySelector('#count').textContent).toBe('0');
|
|
48
|
-
|
|
49
|
-
container.querySelector('#btn').click();
|
|
50
|
-
flushSync();
|
|
51
|
-
|
|
52
|
-
expect(container.querySelector('#count').textContent).toBe('1');
|
|
53
|
-
});
|
|
54
|
-
});
|