Skip to content
6 changes: 4 additions & 2 deletions content/1-reactivity/1-declare-state/ripple/Name.ripple
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { track } from "ripple";

export component Name() {
let $name = "John";
let name = track("John");

<h1>{`Hello ${$name}`}</h1>
<h1>{`Hello ${@name}`}</h1>
}
8 changes: 5 additions & 3 deletions content/1-reactivity/2-update-state/ripple/Name.ripple
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { track } from "ripple";

export component Name() {
let $name = "John";
$name = "Jane";
let name = track("John");
@name = "Jane";

<h1>{`Hello ${$name}`}</h1>
<h1>{`Hello ${@name}`}</h1>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { track } from "ripple";

export component DoubleCount() {
let $count = 10;
const $doubleCount = $count * 2;
let count = track(10);
const doubleCount = track(() => @count * 2);

<div>{$doubleCount}</div>
<div>{@doubleCount}</div>
}
18 changes: 10 additions & 8 deletions content/2-templating/6-conditional/ripple/TrafficLight.ripple
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { track } from "ripple";

const TRAFFIC_LIGHTS = ["red", "orange", "green"];

export component TrafficLight() {
let $lightIndex = 0;
let lightIndex = track(0);

const $light = TRAFFIC_LIGHTS[$lightIndex];
const light = track(() => TRAFFIC_LIGHTS[@lightIndex]);

function nextLight() {
$lightIndex = ($lightIndex + 1) % TRAFFIC_LIGHTS.length;
@lightIndex = (@lightIndex + 1) % TRAFFIC_LIGHTS.length;
}

<button onClick={nextLight}>{"Next light"}</button>
<p>{`Light is ${$light}`}</p>
<p>{`Light is ${@light}`}</p>
<p>
{"You must"}
if ($light === "red") {
{"You must "}
if (@light === "red") {
<span>{"STOP"}</span>
} else if ($light === "orange") {
} else if (@light === "orange") {
<span>{"SLOW DOWN"}</span>
} else if ($light === "green") {
} else if (@light === "green") {
<span>{"GO"}</span>
}
Comment on lines +18 to +24
Copy link

@Malix-Labs Malix-Labs Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if pattern matching works for Ripple, but it would be a good use-case, especially since light should be an enum

Suggested change
if (@light === "red") {
<span>{"STOP"}</span>
} else if (@light === "orange") {
<span>{"SLOW DOWN"}</span>
} else if (@light === "green") {
<span>{"GO"}</span>
}
switch (@light) {
case "red":
<span>{"STOP"}</span>
case "orange":
<span>{"SLOW DOWN"}</span>
case "green":
<span>{"GO"}</span>
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch statements arent implemented as of now, though they are planned :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks!
I couldn't find the tracker for it in https://github.com/trueadm/ripple/issues

</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@

import { track } from "ripple";
import { AnswerButton } from "./AnswerButton.ripple";

export component App() {
let $isHappy = true;
let isHappy = track(true);

function onAnswerNo() {
$isHappy = false;
@isHappy = false;
}

function onAnswerYes() {
$isHappy = true;
@isHappy = true;
}

<p>{`Are you happy?`}</p>
<AnswerButton onYes={onAnswerYes} onNo={onAnswerNo} />
<p style="font-size: 50px;">{$isHappy ? "😀" : "😥"}</p>
<p style="font-size: 50px;">{@isHappy ? "😀" : "😥"}</p>
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export component FunnyButton({ $children }) {
export component FunnyButton(props) {
<button
style="background: rgba(0, 0, 0, 0.4); color: #fff; padding: 10px 20px; font-size: 30px; border: 2px solid #fff; margin: 8px; transform: scale(0.9); box-shadow: 4px 4px rgba(0, 0, 0, 0.4); transition: transform 0.2s cubic-bezier(0.34, 1.65, 0.88, 0.925) 0s; outline: 0;"
>
<$children />
<props.children />
</button>
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export component FunnyButton({ $children }) {
export component FunnyButton(props) {
<button
style="background: rgba(0, 0, 0, 0.4); color: #fff; padding: 10px 20px; font-size: 30px; border: 2px solid #fff; margin: 8px; transform: scale(0.9); box-shadow: 4px 4px rgba(0, 0, 0, 0.4); transition: transform 0.2s cubic-bezier(0.34, 1.65, 0.88, 0.925) 0s; outline: 0;"
>
if ($children) {
<$children />
if (props.children) {
<props.children />
} else {
<span>{"No content found"}</span>
}
Expand Down
10 changes: 6 additions & 4 deletions content/6-form-input/1-input-text/ripple/InputHello.ripple
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { track } from "ripple";

export component InputHello() {
let $text = "Hello world";
let text = track("Hello world");

function handleChange(event) {
$text = event.target.value;
@text = event.target.value;
}

<p>{$text}</p>
<input value={$text} onInput={handleChange} />
<p>{@text}</p>
<input value={@text} onInput={handleChange} />
}
8 changes: 5 additions & 3 deletions content/6-form-input/2-checkbox/ripple/IsAvailable.ripple
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { track } from "ripple";

export component IsAvailable() {
let $isAvailable = false;
let isAvailable = track(false);

function handleChange() {
$isAvailable = !$isAvailable;
@isAvailable = !@isAvailable;
}

<input
id="is-available"
type="checkbox"
checked={$isAvailable}
checked={@isAvailable}
onChange={handleChange}
/>
<label for="is-available">{`Is available`}</label>
Expand Down
12 changes: 7 additions & 5 deletions content/6-form-input/3-radio/ripple/PickPill.ripple
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { track } from "ripple";

export component PickPill() {
let $picked = "red";
let picked = track("red");

function handleChange(event) {
$picked = event.target.value;
@picked = event.target.value;
}

<div>{`Picked: ${$picked}`}</div>
<div>{`Picked: ${@picked}`}</div>

<input
id="blue-pill"
checked={$picked === "blue"}
checked={@picked === "blue"}
type="radio"
value="blue"
onChange={handleChange}
Expand All @@ -18,7 +20,7 @@ export component PickPill() {

<input
id="red-pill"
checked={$picked === "red"}
checked={@picked === "red"}
type="radio"
value="red"
onChange={handleChange}
Expand Down
8 changes: 5 additions & 3 deletions content/6-form-input/4-select/ripple/ColorSelect.ripple
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { track } from "ripple";

const colors = [
{ id: 1, text: "red" },
{ id: 2, text: "blue" },
Expand All @@ -6,13 +8,13 @@ const colors = [
];

export component ColorSelect() {
let $selectedColorId = 2;
let selectedColorId = track(2);

function handleChange(event) {
$selectedColorId = event.target.value;
@selectedColorId = event.target.value;
}

<select value={$selectedColorId} onChange={handleChange}>
<select value={@selectedColorId} onChange={handleChange}>
for (const color of colors) {
<option value={color.id} disabled={color.isDisabled}>
{color.text}
Expand Down