Binding cheat sheet

// To assign a property called mydiv on the binding context that contains a div
// element
<div ref="mydiv"></div>

// Binding using translations

// Binding in textContent

Binding directions

// Once binding
<my-component greeting.once="greeting"></my-component>

// One way binding

// Two way binding
<input value.two-way="person.lastName" />

// Using bind expression
<input value.bind="person.age" type="number" />

Event binding

// Simple event binding

// Event binding with muliple parameters
<button"onEvent($event, $context, "Hello World")">Event</button>

// Event binding, targeting component method
<button"[my-component].greet('hello kieran')">Call Greet</button>

Attribute binding

// Standard attribute binding
<div data-value.attr="age"></div>

// Toggle attribute using "true" and "false"
<button click.attr.toggle="[this](aria-expanded='true')">Toggle Expanded</button>

// Add and remove attribute using toggle
<button click.attr.toggle="[this](data-hidden)">Toggle Hidden</button>

// Simple conditional attribute binding. Set if value passes, remove if not
<div data-value.if="age < 20 ? 'young'"></div>

// Simple conditional attribute binding with if / else
<div data-value.if="age < 20 ? 'young' : 'old'"></div>

// Attribute case condition binding with default value
<div"age < 20: 'young', age < 30: 'mid', default: 'old'"></div>

// Attribute case condition binding without default value
<div"age < 20: 'young', age < 30: 'mid'"></div>

Array binding

<template for="item of items">

Class list binding

// Toggle classlist on event
<button click.classlist.toggle="[this]('blue', 'white')"></button>

// Conditional classlist
<div class="color" classlist.if="background == 'red' ? 'red'"></div>

// Using multiple classes
<div classlist.if="color == 'red' ? ['white', 'green'] : ['blue', 'yellow']"></div>

// Classlist case
<div"color=='red': 'red', color=='blue': 'blue', default: 'green'">

Set value

// Toggle global value
<button click.setvalue="$globals.menuVisible = !$globals.menuVisible">

// Toggle context property
<button click.setvalue="state2 = !state2">

// Simple set value
<button click.setvalue="state = 'on'">

// Conditional set value
<button click.setvalue="state = state == 'on' ? 'off' : 'on'">

// Set context property to element property
<button click.setvalue="state = prop(#input, value, true)">

// Set context property based on element condition
<button click.setvalue="state = prop(#input, value, true)==1 ? 'off' : 'on'">

// Set attribute value 
<button click.setvalue="attr(#static1, data-value, true) = 'on'">

// Set attribute to attribute
click.setvalue="attr(#static1, data-value, true) = attr($element, data-value, true)">

// Set element property based on this element's property
<input change.setvalue="prop(#input2, value, true) = prop($element, value)"/>


// use event aggregation emit with event key
<button click.emit="my_event">

// emit with parameters
<button click.emit="my_event(title='hello world', $event, contacts=${contacts})">

// post message to component with id "#selector" with event key of "my_event"
<button"my_event['#selector'](title='hello world')">

// call a process api module
click.process="{type: 'console', action: 'log', {messages: ['hello', 'world']}}">

// call a process api module from a defined schema
<button click.process="schema_name[process_name(param1: 10, param2: 'B')]">