20
loading...
This website collects cookies to deliver better user experience
jQuery
or document.querySelector
. <button-x>
<script>
if (uiSignals.updateClass) {
props.className = 'some-class'
}
props.onClick = () => {
uiSignals.updateClass = true
}
</script>Click
</button-x>
<button-x>
<script>
if (uiSignals.updateClass) {
props.className = 'some-class'
}
props.onClick = () => {
uiSignals.updateClass = !uiSignals.updateClass
}
</script>Click
</button-x>
Note: The snippets are made using a concept called "extended tags". Below you'll be seeing a global uiSignals
object being accessed in embedded <script>
s. You can freerly set/get properties on/of this object. Think of it as a local UI state, something you'd see in React as hooks. What matters the most is that when a property of uiSignals
changes, only the DOM elements which access it get updated.
<span-x>
<script>
if (uiSignals! || uiSignals.activeTab === 'a') {
props.className = 'active'
}
props.onClick = () => {
uiSignals.activeTab = 'a'
}
</script>Default tab (A)
</span-x>
<span-x>
<script>
if (uiSignals.activeTab === 'b') {
props.className = 'active'
}
props.onClick = () => {
uiSignals.activeTab = 'b'
}
</script>B
</span-x>
<span-x>
<script>
if (uiSignals.activeTab === 'c') {
props.className = 'active'
}
props.onClick = () => {
uiSignals.activeTab = 'c'
}
</script>C
</span-x>
<div>
<button-x>
<script>
props.onClick = () => {
uiSignals.shouldTheSpanBeRemoved = true
}
</script>
</button-x>
<span-x gc-as="conditional">
<script>
props.isConditionMet = uiSignals.shouldTheSpanBeRemoved
</script>
</span-x>
</div>
<div>
<input-x>
<script>
props.onKeyUp = async (e) => {
if (e.code === 'Enter') {
await actions.submitRecord(e.target.value)
actions.reload()
}
}
</script>
</input-x>
<ul>
<li gc-as="listItemPresenter" gc-provider="getSomeRecords">
<fragment gc-as="varPresenter" name="getSomeRecordsItem">repeated item</fragment>
</li>
</ul>
</div>
There are some more directives in this snippet which you can read about here. Note that when an extended tag is placed inside a "list item presenter", you get access to a variable called: providerName + Item
, in our case getSomeRecordsItem
which is an item while looping over getSomeRecords
action result (an array). You could also access getSomeRecordsIndex
for a numeric index in the array.
tagName + '-x'
and has an embedded <script>
included. Its code is sandboxed allowing you to access variables which are available inside other directives including slots or list item presenters. In the script you can assign to props
variable to change props/attributes of the "extended" tag. For a complete list of the directives click here.