Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<img src="assets/logo.svg" width="96" height="96" alt="">

# ReactiveScript

A small language for reactive UIs that carries
Expand Down
13 changes: 13 additions & 0 deletions assets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Logo

`logo.svg` is `r = x`: the name read as an equation, `=` being how .rx writes
one (an equation stays true). The two bars are two colours, two values held
equal.

- Tile `#12233D`, corner radius 22 of 100. On a dark ground the tile can be
`#1F3B63`.
- Letters `#FFFFFF`, JetBrains Mono ExtraBold at 38/100, outlined to paths, so
the SVG needs no font.
- Top bar `#5B9BE6`, bottom bar `#F0B44C`, 7/100 thick with round caps.

`tooling/vscode-rx/icon.png` is this SVG rendered at 256 px.
8 changes: 8 additions & 0 deletions assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions guide/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ submitted, close a menu, clear an error), give it its own instant: `onFlush(() =
compiler can't tell a reset from a write that should wait with the rest, such as a tab highlight that moves with its
page, so it's your call. Decide it for each write that sits next to work that loads.

```
```rx
// submit a todo: the input clears now, the row shows as a guess until the server answers
let t = text
onFlush(() => { text := "" })
Expand All @@ -32,7 +32,7 @@ addTodo(t)

## 1. Reading from the server: an equation

```
```rx
forecast = city == "" ? null : city.length < 3 ? throw TooShort(city) : await fetchForecast(city)
```

Expand All @@ -59,7 +59,7 @@ forecast = city == "" ? null : city.length < 3 ? throw TooShort(city) : await fe

## 3. Writing to the server: an action

```
```rx
export source profile: Profile = await loadProfile() // a source with a question: it can take a guess
export source saveError: string = ""

Expand Down Expand Up @@ -95,7 +95,7 @@ by what the screen should do:

When several actions can each change a different row of one list, guess the row, not the list:

```
```rx
export source todos: Todo[] key id = await loadTodos()

export action markDone(id: number) {
Expand Down Expand Up @@ -136,7 +136,7 @@ A guess on a value whose question reads a selection holds the selection with it:
something else waits for the server, and the screen stays on the old choice until the action ends (F-1). Keep the
pending items in a source of their own, with a constant question, and show them beside the loaded ones:

```
```rx
source photo: number := 1
tags = await loadTags(photo)
source adding: { photo: number; tag: string }[] = []
Expand Down Expand Up @@ -169,7 +169,7 @@ and the screen reads only the top:

`examples/todos.rx` is the whole app:

```
```rx
server = await loadTodos() // 1. what the server has: re-asked after every write
source failures: Failure[] := [] // outlives a reset: kept until a retry is accepted
source todos: Row[] key id = withFailures(server, failures) // 2. the client's layer; 3. row guesses go on it
Expand Down
10 changes: 5 additions & 5 deletions guide/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ code.

## Modules

```
```rx
import pure { fetchUser } from "./api" // a loader: callable anywhere, re-asked when its inputs change
import { saveUser } from "./api" // io: callable only in imperative code (handlers, actions, effects)
import { Avatar } from "./Avatar.rx" // another .rx module
Expand All @@ -21,7 +21,7 @@ does (`export action select(id) { selected := id }`, or an action passed as a pr

## Declarations

```
```rx
source count: number := 0 // state; written only with `:=` in imperative code
source user = await fetchUser(id) // state with a question: re-asked when `id` changes, can take a guess
double = count * 2 // an equation: always equal to its right side, never written
Expand Down Expand Up @@ -57,7 +57,7 @@ values. Arrays and strings have their usual methods: `xs.filter(f)`, `xs.map(f)`

A component body is declarations, then markup. JSX is verbatim; control flow is braced:

```
```rx
component IssueList(props: { issues: Issue[] }) {
source open := true
<section>
Expand Down Expand Up @@ -87,7 +87,7 @@ component IssueList(props: { issues: Issue[] }) {

Handlers, `action` bodies and `effect` apply blocks:

```
```rx
<button onClick={() => { count := count + 1 }}>+</button>

effect (count) { log($0) } // runs after `count` changes; `$0` is its value (async.md §6)
Expand All @@ -106,7 +106,7 @@ effect (count) { log($0) } // runs after `count` changes; `$0` is its value (a

## Components

```
```rx
component Card(props: { title: string; children: View }) {
source open := false
<div onClick={() => { open := !open }}>
Expand Down
10 changes: 5 additions & 5 deletions scenarios/S-action-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Rules: AC-7, AC-1, AC-3, W-6, R-f-6.

## Program

```
```rx
export default component App() {
source cart = [1, 2]
source status := ""
Expand Down Expand Up @@ -45,7 +45,7 @@ a failed action: the action handled it.

## Variant: a panic ends the body — the held writes still commit

```
```rx
export default component App() {
source cart = [1, 2]
source status := ""
Expand Down Expand Up @@ -76,7 +76,7 @@ rejection or a `throw` the body does not catch is a compile error (below).

## Variant: throw caught in a plain handler

```
```rx
export default component App() {
source status := ""

Expand All @@ -90,7 +90,7 @@ export default component App() {

## Rejected variants

```
```rx
-- reject: UNCAUGHT_ACTION_FAILURE
export default component App() {
source cart = [1, 2]
Expand All @@ -111,7 +111,7 @@ R-f-6: the rejection of `fetch("checkout")` (a JS promise: `fails(Error)`)
leaves the body uncaught, and nothing can catch it after — the handler
that launched the action does not await it.

```
```rx
-- reject: UNCAUGHT_ACTION_FAILURE
error Declined(reason)
export default component App() {
Expand Down
10 changes: 5 additions & 5 deletions scenarios/S-action-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authoritative view), `tests/until.test.ts`.

## Program

```
```rx
export default component App() {
source name := "Ann" // the truth, as a live channel pushes it
source shown = name
Expand Down Expand Up @@ -55,7 +55,7 @@ The truth is already `Ann`: `until` resolves at once.

## Rejected variants

```
```rx
-- reject: IO_IN_REACTIVE
export default component App() {
source ok := false
Expand All @@ -67,7 +67,7 @@ export default component App() {
`until` waits for the world; it is called from imperative scope (Solid:
"Cannot call until inside a reactive scope").

```
```rx
-- reject: UNTIL_PREDICATE
export default component App() {
source ok := false
Expand All @@ -79,7 +79,7 @@ export default component App() {
The argument is a predicate, `() => e`: a value is read once, and would never
change.

```
```rx
-- reject: REACTIVE_WRITE_IN_OWNED_SCOPE
export default component App() {
source ok := false
Expand All @@ -90,7 +90,7 @@ export default component App() {

The predicate is reactive scope: it reads; it does not write.

```
```rx
-- reject: UNCAUGHT_ACTION_FAILURE
export default component App() {
source id := 1
Expand Down
2 changes: 1 addition & 1 deletion scenarios/S-action-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ compiled .rx show `1` at instant 1; the interpreter showed `3`.

## Program

```
```rx
export default component App() {
source n := 0
source guess = n
Expand Down
2 changes: 1 addition & 1 deletion scenarios/S-action-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Solid and compiled .rx show `0` at instant 3; the interpreter showed `5`.

## Program

```
```rx
export default component App() {
source n := 0
source guess = n
Expand Down
4 changes: 2 additions & 2 deletions scenarios/S-ai-feed.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ change and lands with the body's end (AC-7).

## Rejected variants

```
```rx
-- reject: OPTIMISTIC_NO_QUESTION
-- handler: pick()
export default component App() {
Expand All @@ -74,7 +74,7 @@ export default component App() {

`selected` is declared with `:=` — it has no question for a guess to confirm against (ST-5c).

```
```rx
-- reject: RG-7b
context room: number
component Room(props: { id: number }) {
Expand Down
8 changes: 4 additions & 4 deletions scenarios/S-await-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Rules: R-1, E-11, R-7, R-f-4, AC-1, AC-7, R-f-6.

## Program

```
```rx
error Declined(reason: string) => `declined: ${reason}`
component Badge(props: { v: string }) {
<b>{props.v}</b>
Expand Down Expand Up @@ -50,7 +50,7 @@ action's end. Instant 5: the reader re-asks with `more` true; the held

## Variant: a typed catch passes other classes to the `try` around it

```
```rx
error Declined(reason: string) => `declined: ${reason}`
export default component App() {
source status := ""
Expand Down Expand Up @@ -79,7 +79,7 @@ the statement catches it.

## Rejected variants

```
```rx
-- reject: AWAIT_IN_EXPRESSION
export default component App() {
source status := ""
Expand All @@ -94,7 +94,7 @@ AC-1: a run suspends only at a statement — `await e`, `let v = await e`,
either with a `catch`. An `await` inside an imperative expression is
refused: bind it first (`let r = await fetch("checkout")`).

```
```rx
-- reject: UNCAUGHT_ACTION_FAILURE
error Declined(reason: string) => `declined: ${reason}`
export default component App() {
Expand Down
Loading
Loading