Skip to content

Commit dd74f24

Browse files
committed
fix: prevent increment decrement from pruning change handler binding
1 parent f591f61 commit dd74f24

File tree

14 files changed

+465
-3
lines changed

14 files changed

+465
-3
lines changed

.changeset/lemon-plums-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@marko/runtime-tags": patch
3+
---
4+
5+
Ensure increment and decrement assignements don't prune change handler bindings
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"vars": {
3+
"props": {
4+
"$_": "o",
5+
"$init": "t",
6+
"$$pattern2": "n",
7+
"$$bar": "r",
8+
"$$foo2__script": "m",
9+
"$$foo2": "e",
10+
"$$foo": "a",
11+
"$$foo__OR__fooChange__script": "c",
12+
"$$foo__OR__fooChange": "_",
13+
"$$fooChange2": "f"
14+
}
15+
}
16+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Render
2+
```html
3+
<button>
4+
0:0
5+
</button>
6+
```
7+
8+
9+
# Render
10+
```js
11+
container.querySelector("button").click();
12+
```
13+
```html
14+
<button>
15+
1:1
16+
</button>
17+
```
18+
19+
20+
# Render
21+
```js
22+
container.querySelector("button").click();
23+
```
24+
```html
25+
<button>
26+
2:2
27+
</button>
28+
```
29+
30+
31+
# Render
32+
```js
33+
container.querySelector("button").click();
34+
```
35+
```html
36+
<button>
37+
3:3
38+
</button>
39+
```
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Render
2+
```html
3+
<button>
4+
0:0
5+
</button>
6+
```
7+
8+
# Mutations
9+
```
10+
INSERT button
11+
```
12+
13+
# Render
14+
```js
15+
container.querySelector("button").click();
16+
```
17+
```html
18+
<button>
19+
1:1
20+
</button>
21+
```
22+
23+
# Mutations
24+
```
25+
UPDATE button/#text2 "0" => "1"
26+
UPDATE button/#text0 "0" => "1"
27+
```
28+
29+
# Render
30+
```js
31+
container.querySelector("button").click();
32+
```
33+
```html
34+
<button>
35+
2:2
36+
</button>
37+
```
38+
39+
# Mutations
40+
```
41+
UPDATE button/#text2 "1" => "2"
42+
UPDATE button/#text0 "1" => "2"
43+
```
44+
45+
# Render
46+
```js
47+
container.querySelector("button").click();
48+
```
49+
```html
50+
<button>
51+
3:3
52+
</button>
53+
```
54+
55+
# Mutations
56+
```
57+
UPDATE button/#text2 "2" => "3"
58+
UPDATE button/#text0 "2" => "3"
59+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// size: 330 (min) 206 (brotli)
2+
const $pattern2 = _._const(4, ($scope, $pattern) => {
3+
($foo2($scope, $pattern.foo), $fooChange2($scope, $pattern.fooChange));
4+
}),
5+
$bar = _._let(3, ($scope, bar) => {
6+
(_._text($scope[2], bar),
7+
$pattern2($scope, { foo: bar, fooChange: $foo($scope) }));
8+
}),
9+
$foo__OR__fooChange__script = _._script(
10+
"a1",
11+
($scope, { 5: foo, 6: $fooChange }) =>
12+
_._on($scope[0], "click", function () {
13+
$fooChange(++foo);
14+
}),
15+
),
16+
$foo__OR__fooChange = _._or(7, $foo__OR__fooChange__script),
17+
$foo2 = _._const(5, ($scope, foo) => {
18+
(_._text($scope[1], foo), $foo__OR__fooChange($scope));
19+
}),
20+
$fooChange2 = _._const(6, $foo__OR__fooChange);
21+
function $foo($scope) {
22+
return function (v) {
23+
$bar($scope, v);
24+
};
25+
}
26+
(_._resume("a0", $foo), init());
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export const $template = "<button><!>:<!></button>";
2+
export const $walks = /* get, next(1), replace, over(2), replace, out(1) */" D%c%l";
3+
import * as _ from "@marko/runtime-tags/debug/dom";
4+
const $pattern2 = /* @__PURE__ */_._const("$pattern", ($scope, $pattern) => {
5+
$foo2($scope, $pattern.foo);
6+
$fooChange2($scope, $pattern.fooChange);
7+
});
8+
const $bar = /* @__PURE__ */_._let("bar/3", ($scope, bar) => {
9+
_._text($scope["#text/2"], bar);
10+
$pattern2($scope, {
11+
foo: bar,
12+
fooChange: $foo($scope)
13+
});
14+
});
15+
export function $setup($scope) {
16+
$bar($scope, 0);
17+
}
18+
const $foo__OR__fooChange__script = _._script("__tests__/template.marko_0_foo_$fooChange", ($scope, {
19+
foo,
20+
$fooChange
21+
}) => _._on($scope["#button/0"], "click", function () {
22+
$fooChange(++foo);
23+
}));
24+
const $foo__OR__fooChange = /* @__PURE__ */_._or(7, $foo__OR__fooChange__script);
25+
const $foo2 = /* @__PURE__ */_._const("foo", ($scope, foo) => {
26+
_._text($scope["#text/1"], foo);
27+
$foo__OR__fooChange($scope);
28+
});
29+
const $fooChange2 = /* @__PURE__ */_._const("$fooChange", $foo__OR__fooChange);
30+
function $foo($scope) {
31+
return function (v) {
32+
$bar($scope, v);
33+
};
34+
}
35+
_._resume("__tests__/template.marko_0/foo", $foo);
36+
export default /* @__PURE__ */_._template("__tests__/template.marko", $template, $walks, $setup);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as _ from "@marko/runtime-tags/debug/html";
2+
export default _._template("__tests__/template.marko", input => {
3+
const $scope0_id = _._scope_id();
4+
let bar = 0;
5+
const {
6+
foo,
7+
fooChange: $fooChange
8+
} = {
9+
foo: bar,
10+
fooChange: _._resume(function (v) {
11+
bar = v;
12+
}, "__tests__/template.marko_0/foo", $scope0_id)
13+
};
14+
_._html(`<button>${_._escape(foo)}${_._el_resume($scope0_id, "#text/1")}:<!>${_._escape(bar)}${_._el_resume($scope0_id, "#text/2")}</button>${_._el_resume($scope0_id, "#button/0")}`);
15+
_._script($scope0_id, "__tests__/template.marko_0_foo_$fooChange");
16+
_._scope($scope0_id, {
17+
foo,
18+
$fooChange
19+
}, "__tests__/template.marko", 0, {
20+
foo: "2:9",
21+
$fooChange: "9:20"
22+
});
23+
_._resume_branch($scope0_id);
24+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Render
2+
```html
3+
<button>
4+
0:0
5+
</button>
6+
```
7+
8+
9+
# Render
10+
```js
11+
container.querySelector("button").click();
12+
```
13+
```html
14+
<button>
15+
1:1
16+
</button>
17+
```
18+
19+
20+
# Render
21+
```js
22+
container.querySelector("button").click();
23+
```
24+
```html
25+
<button>
26+
2:2
27+
</button>
28+
```
29+
30+
31+
# Render
32+
```js
33+
container.querySelector("button").click();
34+
```
35+
```html
36+
<button>
37+
3:3
38+
</button>
39+
```

0 commit comments

Comments
 (0)