Skip to content

Commit

Permalink
chore: readme up
Browse files Browse the repository at this point in the history
  • Loading branch information
Viacheslav Bereza committed Dec 22, 2023
1 parent b4ba25c commit bacb604
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,35 @@ In practice this makes MobX applications very well optimized out of the box and

## Guide / API

### Class Decorators

#### `@signal`, `@computed`

For convenient OOP-style coding, the clearest and most minimalistic way to describe reactive signals, are decorators. Currently, many mainstream frameworks use decorators for annotations, and we will take advantage of this feature as well.

```typescript
import { signal, computed } from "ya-signals"

class Todo {
id = Math.random()
@signal title = ""
@signal finished = false

toggle() {
this.finished = !this.finished
}
}

class TodoList {
@signal todos = []

@computed
get unfinishedTodoCount() {
return this.todos.filter(todo => !todo.finished).length
}
}
```

### `signal(initialValue)`

The `signal` function creates a new signal. A signal is a container for a value that can change over time. You can read a signal's value or subscribe to value updates by accessing its `.value` property.
Expand Down Expand Up @@ -99,35 +128,6 @@ console.log(fullName.value);

Any signal that is accessed inside the `computed`'s callback function will be automatically subscribed to and tracked as a dependency of the computed signal.

### Class Decorators

#### `@signal`, `@computed`

For convenient OOP-style coding, the clearest and most minimalistic way to describe reactive signals, are decorators. Currently, many mainstream frameworks use decorators for annotations, and we will take advantage of this feature as well.

```typescript
import { signal, computed } from "ya-signals"

class Todo {
id = Math.random()
@signal title = ""
@signal finished = false

toggle() {
this.finished = !this.finished
}
}

class TodoList {
@signal todos = []

@computed
get unfinishedTodoCount() {
return this.todos.filter(todo => !todo.finished).length
}
}
```


### `autorun(fn)`

Expand Down

0 comments on commit bacb604

Please sign in to comment.