@yannosay/sinth 0.16.0 → 0.17.0
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/README.md +3 -3
- package/package.json +1 -1
- package/src/core/compiler.ts +7 -4
- package/src/core/parser.ts +11 -15
package/README.md
CHANGED
|
@@ -133,7 +133,7 @@ Button(onClick: isFullscreen = !isFullscreen, fullscreen: isFullscreen, fullscre
|
|
|
133
133
|
Without fullscreenSync, pressing Escape exits fullscreen but the variable stays true.
|
|
134
134
|
With it, Escape resets the variable to false — button text updates automatically.
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
#### Opt-in DOM Diffing
|
|
137
137
|
|
|
138
138
|
Skip re-executing expressions when their variables haven't changed. Perfect for expensive calculations or side effects you only want to fire once.
|
|
139
139
|
|
|
@@ -146,10 +146,10 @@ var int count = 0
|
|
|
146
146
|
Main {
|
|
147
147
|
Heading(level: 1) { count }
|
|
148
148
|
(alert("Fires only once!")) -- no dependencies, runs once and never again
|
|
149
|
-
Button(onClick: count
|
|
149
|
+
Button(onClick: count += 1) { "Increment" }
|
|
150
150
|
}
|
|
151
151
|
```
|
|
152
|
-
Count updates every click because count changed. The alert fires only on page load — zero dependencies means it's cached forever.
|
|
152
|
+
Count updates every click because count changed. The alert fires only on page load — zero dependencies means it's cached forever. Just a meta flag.
|
|
153
153
|
|
|
154
154
|
|
|
155
155
|
|
package/package.json
CHANGED
package/src/core/compiler.ts
CHANGED
|
@@ -1071,10 +1071,13 @@ export function buildRuntime(opts: {
|
|
|
1071
1071
|
let vars = [];
|
|
1072
1072
|
syncedEls.forEach(function(el) { vars.push(el.dataset.sinthFullscreenSync); });
|
|
1073
1073
|
document.addEventListener('fullscreenchange', function() {
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1074
|
+
let state = !!document.fullscreenElement;
|
|
1075
|
+
vars.forEach(function(varName) {
|
|
1076
|
+
switch(varName) {
|
|
1077
|
+
${[...new Set(varDecls.filter(v => v.name).map(v => `case '${v.name}': ${v.name} = state; break;`))].join('\n ')}
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
sinthRender();
|
|
1078
1081
|
});
|
|
1079
1082
|
}
|
|
1080
1083
|
})();`;
|
package/src/core/parser.ts
CHANGED
|
@@ -104,9 +104,14 @@ sinthRender();`;
|
|
|
104
104
|
continue;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
this.
|
|
109
|
-
|
|
107
|
+
if (nextType === TT.LPAREN && identName[0] === identName[0].toLowerCase()) {
|
|
108
|
+
this.consume(TT.IDENT);
|
|
109
|
+
const expr = this.parseCallExpr({ kind: "variable", name: identName });
|
|
110
|
+
uses.push({ kind: "use", name: "__IF_ROOT__", attrs: [], children: [{ kind: "expr", expression: expr, loc: this.peek().loc }], loc: this.peek().loc });
|
|
111
|
+
} else {
|
|
112
|
+
this.pos = savedPos;
|
|
113
|
+
uses.push(this.parseCompUse());
|
|
114
|
+
}
|
|
110
115
|
}
|
|
111
116
|
else throw new SinthError(
|
|
112
117
|
`Unexpected token '${this.peek().value}' (${TT[this.peek().type]}) at top level`,
|
|
@@ -809,19 +814,10 @@ private parseArrayLiteral(): Literal {
|
|
|
809
814
|
if (identName[0] === identName[0].toUpperCase() && identName[0] !== identName[0].toLowerCase()) {
|
|
810
815
|
children.push(this.parseCompUse());
|
|
811
816
|
} else {
|
|
812
|
-
this.
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
if (!this.check(TT.RPAREN)) {
|
|
816
|
-
args.push(this.parseExpression()!);
|
|
817
|
-
while (this.check(TT.COMMA)) {
|
|
818
|
-
this.consume(TT.COMMA);
|
|
819
|
-
args.push(this.parseExpression()!);
|
|
820
|
-
}
|
|
817
|
+
const expr = this.parseExpression();
|
|
818
|
+
if (expr) {
|
|
819
|
+
children.push({ kind: "expr", expression: expr, loc });
|
|
821
820
|
}
|
|
822
|
-
this.consume(TT.RPAREN);
|
|
823
|
-
const callExpr: Expression = { kind: "call", callee: { kind: "variable", name: identName }, args };
|
|
824
|
-
children.push({ kind: "expr", expression: callExpr, loc });
|
|
825
821
|
}
|
|
826
822
|
continue;
|
|
827
823
|
}
|