Skip to content

Commit

Permalink
chore: readme up
Browse files Browse the repository at this point in the history
  • Loading branch information
betula committed Dec 24, 2023
1 parent 0aeac5a commit 35e95aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
26 changes: 14 additions & 12 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,24 +404,25 @@ const form = useRecipeForm()
[![Edit example in Codesandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/sandbox/nostalgic-galileo-p8ylnf?file=%2Fsrc%2FApp.tsx%3A20%2C1)

```typescript
import { hook, un, type SignalReadonly } from "ya-signals";
import { hook, type SignalReadonly } from "ya-signals";

// Can be object struct with named fields
type Params = [number, string];
type Params = {
count: number;
text: string;
};

class RecipeForm {
constructor(signalParams: SignalReadonly<Params>) {
un(() => {
// destroy
})
class LocalLogic {
constructor($params: SignalReadonly<Params>) {
console.log("constructor with params", $params.value);

signalParams.sync((params) => {
console.log('Current params values', params);
$params.subscribe((params) => {
console.log("updated params", params);
});
}
}

export const useRecipeForm = hook(RecipeForm)
const useLocalLogic = hook(LocalLogic);
```

The `signal` documentation see [here](/DOCUMENTATION.md#signalinitialvalue).
Expand All @@ -432,8 +433,9 @@ And using it somewhere inside React component function
import { useRecipeForm } from './recipe-form.ts';

function Form() {
// Params available here
const form = useRecipeForm([10, 'hello']);
const [count, setCount] = useState(() => 1);
const [text, setText] = useState(() => "Hello");
const logic = useLocalLogic({ count, text });

return <>
// ...
Expand Down
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,25 @@ const form = useRecipeForm()
[![Edit example in Codesandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/sandbox/nostalgic-galileo-p8ylnf?file=%2Fsrc%2FApp.tsx%3A20%2C1)

```typescript
import { hook, un, type SignalReadonly } from "ya-signals";
import { hook, type SignalReadonly } from "ya-signals";

// Can be object struct with named fields
type Params = [number, string];
type Params = {
count: number;
text: string;
};

class RecipeForm {
constructor(signalParams: SignalReadonly<Params>) {
un(() => {
// destroy
})
class LocalLogic {
constructor($params: SignalReadonly<Params>) {
console.log("constructor with params", $params.value);

signalParams.sync((params) => {
console.log('Current params values', params);
$params.subscribe((params) => {
console.log("updated params", params);
});
}
}

export const useRecipeForm = hook(RecipeForm)
const useLocalLogic = hook(LocalLogic);
```

The `signal` documentation see [here](/DOCUMENTATION.md#signalinitialvalue).
Expand All @@ -100,8 +101,9 @@ And using it somewhere inside React component function
import { useRecipeForm } from './recipe-form.ts';

function Form() {
// Params available here
const form = useRecipeForm([10, 'hello']);
const [count, setCount] = useState(() => 1);
const [text, setText] = useState(() => "Hello");
const logic = useLocalLogic({ count, text });

return <>
// ...
Expand Down

0 comments on commit 35e95aa

Please sign in to comment.