begin # Define the template with variable interpolation and event bindings template = <<~HTML

{{ title }}

Current Count: {{ count }}

HTML # Define the reactive state state = { title: "rb-wasm-vdom Example App (Reactivity)", count: 0, step: 1 } # Define the methods to handle events and mutate the state methods = { increment: ->(e, s) { s[:count] += s[:step] }, decrement: ->(e, s) { s[:count] -= s[:step] }, reset: ->(e, s) { s[:count] = 0 }, update_step: ->(e, s) { s[:step] = e[:target][:value].to_i } } # Initialize and mount the application RbWasmVdom.create_app("#app", template: template, state: state, methods: methods) rescue Exception => e message = "#{e.class}: #{e.message}\n#{e.backtrace&.join("\n")}" JS.global[:console].error(message) end