-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs Restructure #40
Draft
voliva
wants to merge
3
commits into
master
Choose a base branch
from
restructure
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Docs Restructure #40
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { bind, Subscribe } from "@react-rxjs/core" | ||
import { createSignal } from "@react-rxjs/utils" | ||
import React, { useRef } from "react" | ||
import { concat, defer } from "rxjs" | ||
import { concatMap, switchMap } from "rxjs/operators" | ||
|
||
const { getTodos, postTodo } = (() => { | ||
let todos = [ | ||
{ | ||
id: 0, | ||
title: "Grocery shopping", | ||
}, | ||
] | ||
|
||
return { | ||
getTodos: async () => todos, | ||
postTodo: async (todo) => { | ||
todos = [ | ||
...todos, | ||
{ | ||
id: todos[todos.length - 1].id + 1, | ||
title: todo, | ||
}, | ||
] | ||
}, | ||
} | ||
})() | ||
|
||
const [todoPost$, addTodo] = createSignal<string>() | ||
|
||
const todoResult$ = todoPost$.pipe(concatMap(postTodo)) | ||
|
||
const [useTodos] = bind( | ||
// When do we need to request todos? | ||
concat( | ||
// 1. One single time when starting | ||
defer(getTodos), | ||
// 2. Every time we have created a new todo | ||
todoResult$.pipe(switchMap(getTodos)), | ||
), | ||
[], | ||
) | ||
|
||
function Todos() { | ||
const todos = useTodos() | ||
|
||
const ref = useRef<HTMLInputElement>() | ||
const handleAddClick = () => { | ||
addTodo(ref.current!.value) | ||
ref.current!.value = "" | ||
ref.current!.focus() | ||
} | ||
|
||
return ( | ||
<div> | ||
<input type="text" defaultValue="Do Laundry" ref={ref} /> | ||
<button onClick={handleAddClick}>Add Todo</button> | ||
|
||
<ul> | ||
{todos.map((todo) => ( | ||
<li key={todo.id}>{todo.title}</li> | ||
))} | ||
</ul> | ||
</div> | ||
) | ||
} | ||
|
||
export default function InvalidateQuery() { | ||
return ( | ||
<Subscribe fallback={<div>Loading...</div>}> | ||
<Todos /> | ||
</Subscribe> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Features | ||
--- | ||
|
||
- Build truly reactive state. | ||
- Makes code-splitting simple. | ||
- Simplifies code navigability. | ||
- First-class support for React Suspense. | ||
- First-class support for Error boundaries. | ||
- Completely decentralized store. | ||
- Built in Typescript. | ||
- Works with any React renderer (React DOM, React Native, etc.). | ||
- No external dependencies. | ||
- Extremely light: 3.4kB parsed, 1.5kB gziped. | ||
- Thin API. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
--- | ||
title: Quick Start | ||
--- | ||
|
||
import CharacterCounter from "./examples/CharacterCounter" | ||
import BrowserOnly from '@docusaurus/BrowserOnly'; | ||
|
||
## Installation | ||
|
||
React-RxJS is published in npm as `@react-rxjs/core`. | ||
We also publish a recommended `@react-rxjs/utils` package with some useful functions to build reactive state streams. | ||
|
||
```sh | ||
npm i rxjs @react-rxjs/core @react-rxjs/utils | ||
``` | ||
|
||
or using yarn | ||
|
||
```sh | ||
yarn add rxjs @react-rxjs/core @react-rxjs/utils | ||
``` | ||
|
||
## Usage | ||
|
||
```tsx | ||
import { map } from "rxjs/operators" | ||
import { bind, Subscribe } from "@react-rxjs/core" | ||
import { createSignal } from "@react-rxjs/utils" | ||
|
||
// A signal is an entry point to react-rxjs. It's equivalent to using a subject | ||
const [textChange$, setText] = createSignal<string>() | ||
|
||
// bind returns a hook to get the value of the observable. | ||
const [useText, text$] = bind(textChange$, "") | ||
|
||
// And it also returns an observable so we can compose this state with other observables | ||
// in here we're making a derived state by calculating the text$'s length. | ||
const [useCharCount, charCount$] = bind( | ||
text$.pipe( | ||
map((text) => text.length) | ||
) | ||
) | ||
|
||
function TextInput() { | ||
// Just use the hook! | ||
const text = useText() | ||
|
||
return ( | ||
<div> | ||
<input | ||
type="text" | ||
value={text} | ||
placeholder="Type something..." | ||
onChange={ | ||
// And trigger the signal | ||
(e) => setText(e.target.value) | ||
} | ||
/> | ||
<br /> | ||
Echo: {text} | ||
</div> | ||
) | ||
} | ||
|
||
function CharacterCount() { | ||
const count = useCharCount() | ||
|
||
return <>Character Count: {count}</> | ||
} | ||
|
||
function CharacterCounter() { | ||
// `Subscribe` manages the subscription lifetime of its children | ||
return ( | ||
<Subscribe> | ||
<TextInput /> | ||
<CharacterCount /> | ||
</Subscribe> | ||
) | ||
} | ||
``` | ||
|
||
### Interactive result | ||
|
||
<BrowserOnly> | ||
{() => <CharacterCounter />} | ||
</BrowserOnly> | ||
|
||
## There's more! | ||
|
||
This is just a simple example of two components sharing a synchronous state. | ||
|
||
React-RxJS gets even more fun when you start using asynchronous state, leveraging Suspense and enhancing code-splitting! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
title: Invalidate Query | ||
--- | ||
|
||
import InvalidateQuery from "../examples/InvalidateQuery" | ||
import BrowserOnly from '@docusaurus/BrowserOnly'; | ||
|
||
```tsx | ||
import { bind, Subscribe } from "@react-rxjs/core" | ||
import { createSignal } from "@react-rxjs/utils" | ||
import { concat, defer } from "rxjs" | ||
import { concatMap, switchMap } from "rxjs/operators" | ||
import { getTodos, postTodo } from "../my-api" | ||
|
||
const [todoPost$, addTodo] = createSignal<string>() | ||
|
||
const todoResult$ = todoPost$.pipe( | ||
concatMap(postTodo) | ||
) | ||
|
||
const [useTodos] = bind( | ||
// When do we need to request todos? | ||
concat( | ||
// 1. One single time when starting | ||
defer(getTodos), | ||
// 2. Every time we have created a new todo | ||
todoResult$.pipe( | ||
switchMap(getTodos) | ||
) | ||
), | ||
[] | ||
) | ||
|
||
function Todos() { | ||
const todos = useTodos() | ||
|
||
const ref = useRef<HTMLInputElement>() | ||
const handleAddClick = () => { | ||
addTodo(ref.current!.value) | ||
ref.current!.value = "" | ||
ref.current!.focus() | ||
} | ||
|
||
return ( | ||
<div> | ||
<input type="text" defaultValue="Do Laundry" ref={ref} /> | ||
<button onClick={handleAddClick}>Add Todo</button> | ||
|
||
<ul> | ||
{todos.map((todo) => ( | ||
<li key={todo.id}>{todo.title}</li> | ||
))} | ||
</ul> | ||
</div> | ||
) | ||
} | ||
|
||
function App() { | ||
return ( | ||
<Subscribe> | ||
<Todos /> | ||
</Subscribe> | ||
) | ||
} | ||
``` | ||
|
||
### Interactive result | ||
|
||
<BrowserOnly> | ||
{() => <InvalidateQuery />} | ||
</BrowserOnly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to have a section highlighting these few features.... things like TS support, React Native, etc., but I feel this feels a bit empty. Dunno