20
loading...
This website collects cookies to deliver better user experience
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta gc-as="navName" gc-name="Home">
<title>Calculator</title>
</head>
<body>
<div gc-as="layout">
<div class="container">
<div gc-as="slot" gc-name="content">
<input-x type="number">
<script>
props.onChange = (e) => {
uiSignals.numberA = parseInt(e.target.value)
}
</script>
</input-x>
<select-x>
<script>
props.onChange = (e) => {
uiSignals.operator = e.target.value
}
</script>
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select-x>
<input-x type="number">
<script>
props.onChange = (e) => {
uiSignals.numberB = parseInt(e.target.value)
}
</script>
</input-x>
<span>=</span>
<input-x type="number">
<script>
switch (uiSignals.operator) {
case '-':
props.value = uiSignals.numberA - uiSignals.numberB
break
case '*':
props.value = uiSignals.numberA * uiSignals.numberB
break
case '/':
props.value = uiSignals.numberA / uiSignals.numberB
break
case '+':
default:
props.value = uiSignals.numberA + uiSignals.numberB
}
</script>
</input-x>
</div>
</div>
</div>
</body>
</html>
tagName + '-x'
and have an embedded <script>
allowing you to access variables available in the scope where they have been placed. The scripts can assign to props
variable to change props/attributes of the extended tag. In this case, you can see writing/reading uiSignals
which holds some sort of observables and it'll update any props they are assigned to. What you see is a meta-framework abstracting away the signals. See SolidJS. uiSignals
are scoped to a slot/partial they are in and an HTML tag is told to be a slot by using one of many HTML directives:<div gc-as="slot" gc-name="content">
...
</div>
[gc-as]
tells what it is and other [gc-*]
attributes are parameters.script
tag in each of the extended tag allows to modify their props e.g. register events or set a value on an input. It modifies only the props of its direct parent tag. <input-x type="number">
<script>
props.onChange = (e) => {
uiSignals.numberA = parseInt(e.target.value)
}
</script>
</input-x>
<select-x>
<script>
props.onChange = (e) => {
uiSignals.operator = e.target.value
}
</script>
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select-x>
<input-x type="number">
<script>
props.onChange = (e) => {
uiSignals.numberB = parseInt(e.target.value)
}
</script>
</input-x>
<input-x type="number">
<script>
switch (uiSignals.operator) {
case '-':
props.value = uiSignals.numberA - uiSignals.numberB
break
case '*':
props.value = uiSignals.numberA * uiSignals.numberB
break
case '/':
props.value = uiSignals.numberA / uiSignals.numberB
break
case '+':
default:
props.value = uiSignals.numberA + uiSignals.numberB
}
</script>
</input-x>