mirror of
https://github.com/MercuryWorkshop/dreamlandjs.git
synced 2025-05-16 07:30:01 -04:00
remove h useless hack
This commit is contained in:
parent
6cd1e1f304
commit
eb6ee2cb8c
3 changed files with 5 additions and 20 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
||||||
examples/lib/
|
examples/lib/
|
||||||
node_modules
|
node_modules
|
||||||
index.js
|
index.js
|
||||||
|
a.js
|
||||||
|
index.html
|
||||||
|
|
19
AliceJS.js
19
AliceJS.js
|
@ -127,25 +127,8 @@ export function useValue(references) {
|
||||||
return reference.proxy[reference.property];
|
return reference.proxy[reference.property];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hack to skip use() when there's only one possible property
|
|
||||||
Object.defineProperty(window, "h", {
|
|
||||||
get: () => {
|
|
||||||
__reference_stack = [];
|
|
||||||
return (type, props, ...children) => {
|
|
||||||
let references = __reference_stack;
|
|
||||||
references[ALICEJS_REFERENCES_MARKER] = true;
|
|
||||||
|
|
||||||
if (references.length == 1 && children.length == 1) {
|
|
||||||
__reference_stack = [];
|
|
||||||
return h(type, props, references);
|
|
||||||
} else {
|
|
||||||
return h(type, props, ...children);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Actual JSX factory. Responsible for creating the HTML elements and all of the *reactive* syntactic sugar
|
// Actual JSX factory. Responsible for creating the HTML elements and all of the *reactive* syntactic sugar
|
||||||
function h(type, props, ...children) {
|
export function h(type, props, ...children) {
|
||||||
if (typeof type === "function") {
|
if (typeof type === "function") {
|
||||||
let newthis = stateful({});
|
let newthis = stateful({});
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ function App() {
|
||||||
<div>
|
<div>
|
||||||
<button on:click={() => this.counter++} >Click me!</button>
|
<button on:click={() => this.counter++} >Click me!</button>
|
||||||
<p>
|
<p>
|
||||||
{this.counter}
|
{use(this.counter)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -39,7 +39,7 @@ function App() {
|
||||||
<div>
|
<div>
|
||||||
<button onClick={increase}>Click me!</button>
|
<button onClick={increase}>Click me!</button>
|
||||||
<p>
|
<p>
|
||||||
Value: {use(this.counter)}
|
Value: {counter}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue