implement
Implement/Signals/Signal helper methods

In the previous lesson we used the .increment() method to update our count signal. This is one of the many mutation helpers we provide on signal.

Working with signals with just .set() and .update() isn't the best experience, so we include helper methods for mutating signals depending on their type:

MethodType
.toggle()boolean
.increment()number
.decrement()number
.push()T[]
.pop()T[]
.unshift()T[]
.shift()T[]
.splice()T[]

Try using the .push() method to add an item to items when we click the button.

function addItem() {
	items.push("new item");
}
index.ts
import { Button, Div, signal, P } from "@implementjs/core";

export default function App() {
	const items = signal<string[]>([]);

	function addItem() {}

	return Div(
		Button({ onClick: addItem }, "Add Item"),
		// don't worry too much about this right now, we'll explain it later
		P(items.bind((items) => JSON.stringify(items))),
	);
}
Preview