Functions
Once you have some cells, you can compute values based on those cells using normal functions.
tsx
import {Cell } from "@starbeam/universal";constname =Cell ("John");constlocation =Cell ("New York");functiondescription () {return `${name .current } lives in ${location .current }`;}
tsx
import {Cell } from "@starbeam/universal";constname =Cell ("John");constlocation =Cell ("New York");functiondescription () {return `${name .current } lives in ${location .current }`;}
tsx
import {Cell } from "@starbeam/universal";constname =Cell ("John");constlocation =Cell ("New York");functiondescription (): string {return `${name .current } lives in ${location .current }`;}
tsx
import {Cell } from "@starbeam/universal";constname =Cell ("John");constlocation =Cell ("New York");functiondescription (): string {return `${name .current } lives in ${location .current }`;}
And then use the function as normal.
tsx
description ();// "John lives in New York"name .set ("John Doe");description ();// "John Doe lives in New York"location .set ("Los Angeles");description (); // "John Doe lives in Los Angeles"
tsx
description ();// "John lives in New York"name .set ("John Doe");description ();// "John Doe lives in New York"location .set ("Los Angeles");description (); // "John Doe lives in Los Angeles"
You can also pass cells into functions as arguments.
tsx
functiondescription (name ) {return `${name .current } lives in ${location .current }`;}
tsx
functiondescription (name ) {return `${name .current } lives in ${location .current }`;}
tsx
functiondescription (name :Cell <string>): string {return `${name .current } lives in ${location .current }`;}
tsx
functiondescription (name :Cell <string>): string {return `${name .current } lives in ${location .current }`;}
And then use the function as normal.
tsx
description (name ); //=> "John lives in New York"name .set ("John Doe");description (name ); //=> "John Doe lives in New York"location .set ("Los Angeles");description (name ); //=> "John Doe lives in Los Angeles"
tsx
description (name ); //=> "John lives in New York"name .set ("John Doe");description (name ); //=> "John Doe lives in New York"location .set ("Los Angeles");description (name ); //=> "John Doe lives in Los Angeles"