-
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 2 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,16 @@ | ||
--- | ||
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. | ||
- No centralized store. | ||
- No state context provider. | ||
- Built in Typescript. | ||
- Works with React DOM and React Native. | ||
- No external dependencies. | ||
- Extremely light: 3.4kB parsed, 1.5kB gziped. | ||
- Thin API. |
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 |
---|---|---|
@@ -1,38 +1,48 @@ | ||
--- | ||
title: Getting Started | ||
title: Quick Start | ||
--- | ||
|
||
import CharacterCounter from "./examples/CharacterCounter" | ||
import BrowserOnly from '@docusaurus/BrowserOnly'; | ||
|
||
## Installation | ||
|
||
React-RxJS is published in npm as `@react-rxjs/core` | ||
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 | ||
npm i rxjs @react-rxjs/core @react-rxjs/utils | ||
``` | ||
|
||
or using yarn | ||
|
||
```sh | ||
yarn add rxjs @react-rxjs/core | ||
yarn add rxjs @react-rxjs/core @react-rxjs/utils | ||
``` | ||
|
||
## Create a hook from an observable | ||
|
||
`@react-rxjs/core` exports a function called `bind` which is used to connect a stream to a hook. | ||
## Usage | ||
|
||
```tsx | ||
import { bind } from "@react-rxjs/core" | ||
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(); | ||
|
||
// 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 ( | ||
|
@@ -41,48 +51,30 @@ function TextInput() { | |
type="text" | ||
value={text} | ||
placeholder="Type something..." | ||
onChange={(e) => setText(e.target.value)} | ||
onChange={ | ||
// And trigger the signal | ||
(e) => setText(e.target.value) | ||
} | ||
/> | ||
<br /> | ||
Echo: {text} | ||
</div> | ||
) | ||
} | ||
``` | ||
|
||
`bind` returns a tuple that contains the hook, plus the underlying shared observable so it can be used by other streams: | ||
|
||
```tsx | ||
import { map } from "rxjs/operators" | ||
import { bind, Subscribe } from "@react-rxjs/core" | ||
|
||
// Previously... | ||
// const [useText, text$] = bind(...); | ||
|
||
const [useCharCount, charCount$] = bind( | ||
text$.pipe( | ||
map((text) => text.length) | ||
) | ||
) | ||
|
||
function CharacterCount() { | ||
const count = useCharCount() | ||
|
||
return <>Character Count: {count}</> | ||
} | ||
``` | ||
|
||
Something to note is that a subscription on the underlying observable must be present before the hook is executed. We can use `Subscribe` to help us with it: | ||
|
||
```tsx | ||
function CharacterCounter() { | ||
// `Subscribe` manages the subscription lifetime of its children | ||
return ( | ||
<div> | ||
<Subscribe source$={charCount$}> | ||
<TextInput /> | ||
<CharacterCount /> | ||
</Subscribe> | ||
</div> | ||
<Subscribe> | ||
<TextInput /> | ||
<CharacterCount /> | ||
</Subscribe> | ||
) | ||
} | ||
``` | ||
|
@@ -93,7 +85,8 @@ The interactive result: | |
{() => <CharacterCounter />} | ||
</BrowserOnly> | ||
|
||
## Next steps | ||
## There's more! | ||
|
||
This is just a simple example of two components sharing a synchronous state. | ||
|
||
We strongly recommend reading through [core concepts](core-concepts.md) to | ||
understand the mindset of this library. | ||
React-RxJS gets even more fun when you start using asynchronous state, leveraging Suspense and enhancing code-splitting! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unsure on the casual register I took in here, maybe it's too much. I'd like to make readers keep following the next few examples There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like it! |
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