Skip to content

Commit b84587d

Browse files
committed
feat: implement return init from lifecycle onMount
1 parent 9c3f20a commit b84587d

File tree

23 files changed

+372
-13
lines changed

23 files changed

+372
-13
lines changed

.changeset/eager-pets-grin.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+
Add ability for the lifecycle onMount hook to spread values into this object by returning.

.sizes.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
{
88
"name": "*",
99
"total": {
10-
"min": 19644,
11-
"brotli": 7530
10+
"min": 19674,
11+
"brotli": 7562
1212
}
1313
},
1414
{

.sizes/dom.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// size: 19644 (min) 7530 (brotli)
1+
// size: 19674 (min) 7562 (brotli)
22
var empty = [],
33
rest = Symbol();
44
function attrTag(attrs) {
@@ -1134,11 +1134,13 @@ function normalizeString(value) {
11341134
}
11351135
function _lifecycle(scope, index, thisObj) {
11361136
let instance = scope[index];
1137-
instance
1138-
? (Object.assign(instance, thisObj), instance.onUpdate?.())
1139-
: ((scope[index] = thisObj),
1140-
thisObj.onMount?.(),
1137+
if (instance) (Object.assign(instance, thisObj), instance.onUpdate?.());
1138+
else {
1139+
scope[index] = thisObj;
1140+
let newProps = thisObj.onMount?.();
1141+
(Object.assign(thisObj, newProps),
11411142
($signal(scope, "K" + index).onabort = () => thisObj.onDestroy?.()));
1143+
}
11421144
}
11431145
function removeChildNodes(startNode, endNode) {
11441146
let stop = endNode.nextSibling,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tried to overwrite existing property "w" in $lifecycle onMount.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tried to overwrite existing property "w" in $lifecycle onMount.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const $template = "";
2+
export const $walks = "";
3+
import * as _ from "@marko/runtime-tags/debug/dom";
4+
const $setup__script = _._script("__tests__/template.marko_0", $scope => _._lifecycle($scope, "$lifecycle", {
5+
w: 0,
6+
onMount: function () {
7+
this.w = 1;
8+
}
9+
}));
10+
export const $setup = $setup__script;
11+
export default /* @__PURE__ */_._template("__tests__/template.marko", $template, $walks, $setup);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as _ from "@marko/runtime-tags/debug/html";
2+
export default _._template("__tests__/template.marko", input => {
3+
const $scope0_id = _._scope_id();
4+
_._script($scope0_id, "__tests__/template.marko_0");
5+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<lifecycle
2+
w=0
3+
onMount() {
4+
this.w = 1;
5+
}
6+
/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { wait } from "../../utils/resolve";
2+
3+
export const steps = [{}, wait(1)];
4+
5+
export const error_runtime = true;
6+
export const skip_ssr = true;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"vars": {
3+
"props": {
4+
"$_": "t",
5+
"$init": "n",
6+
"$$x__script": "o",
7+
"$$x": "i"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)