Skip to content

Commit

Permalink
Merge branch 'main' into 1012
Browse files Browse the repository at this point in the history
  • Loading branch information
overthemike authored Dec 17, 2024
2 parents 704f065 + 84d109d commit 982a09f
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 33 deletions.
19 changes: 11 additions & 8 deletions docs/api/advanced/snapshot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ This should be fine, because the expectation is that they execute very quickly (

## Vanilla JavaScript

In VanillaJS, `snapshot` is not necessary to access proxied object values, inside or outside of subscribe. However, it is useful, for example, to keep a serializable list of unproxied objects or check if objects have changed. It also resolves promises.
In VanillaJS, `snapshot` is not necessary to access proxied object values, inside or outside of subscribe. However, it is useful, for example, to keep a serializable list of un-proxied objects or check if objects have changed. It also resolves promises.

<br />

> 💡 Tip
>
> If you are using valtio outside of react, import from `valtio/vanilla`
>
> ```js
> import { proxy, snapshot } from 'valtio/vanilla'
> ```
<blockquote className="tip">
💡 Tip

If you are using valtio outside of react, import from `valtio/vanilla`

```js
import { proxy, snapshot } from 'valtio/vanilla'
```

</blockquote>
14 changes: 9 additions & 5 deletions docs/api/basic/useSnapshot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,15 @@ In dev mode, `useSnapshot` uses React's `useDebugValue` to output a list of fiel

<br />

> !! &nbsp; There are two disclaimers to
> using the debug value
>
> 1. Due to the way `useSnapshot` uses a proxy to recorded accesses _after_ `useSnapshot` has returned, the fields listed in `useDebugValue` are technically from the _previous_ render.
> 2. Object getter and class getter calls are not included in the `useDebugValue` output, but don't worry, they are actually correctly tracked internally and correctly trigger re-renders when changed.
<blockquote className="important">
!! &nbsp; There are two disclaimers to using the debug value

1. Due to the way `useSnapshot` uses a proxy to recorded accesses _after_ `useSnapshot` has returned, the fields listed in `useDebugValue` are technically from the _previous_ render.
2. Object getter and class getter calls are not included in the `useDebugValue` output, but don't worry, they are actually correctly tracked internally and correctly trigger re-renders when changed.

</blockquote>

<br />

<br />

Expand Down
4 changes: 2 additions & 2 deletions docs/api/hacks/internals.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ description: ''
Valtio exposes some internal capabilities.
This isn't for app developers. Use it at your own risk.

# unstable_getInternalStates
# `unstable_getInternalStates`

This function exposes the internal states. Modifying such states may result in wrong behaviors. You need to understand the [source code](https://github.com/pmndrs/valtio/blob/main/src/vanilla.ts) thoroughly to use it.

# unstable_replaceInternalFunction
# `unstable_replaceInternalFunction`

This function exposes a way to replace some internal functions. It can easily break things. You need to understand the [source code](https://github.com/pmndrs/valtio/blob/main/src/vanilla.ts) thoroughly to use it.
17 changes: 13 additions & 4 deletions docs/guides/computed-properties.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ In Valtio you can use object & class getters and setters to create computed prop

<br />

> ℹ️ &nbsp; Note
> Getters in JavaScript are a more advanced feature of the language, so Valtio recommends using them with caution. That said, if you are a more advanced JavaScript programmer, they should work as you expect; see the "Note about using `this`" section below.
<blockquote className="note">
ℹ️ &nbsp; Note

Getters in JavaScript are a more advanced feature of the language, so Valtio recommends using them with caution. That said, if you are a more advanced JavaScript programmer, they should work as you expect; see the "Note about using `this`" section below.

</blockquote>
<br />

<br />

Expand Down Expand Up @@ -42,8 +47,12 @@ However, when you make a snapshot, calls to `snap.doubled` are effectively cache

<br />

> ℹ️ &nbsp; Note
> In the current implementation a computed property should only reference \*\*\_sibling\*\*\* properties, otherwise you'll encounter weird bugs. For example:
<blockquote className="note">
ℹ️ &nbsp; Note

In the current implementation a computed property should only reference \*\*\_sibling\*\*\* properties, otherwise you'll encounter weird bugs. For example:

</blockquote>

<br />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ export { state, useSnapshot, subscribe }

<br />

> 💡 &nbsp; Using TypeScript? Here are some links for reference
>
> https://www.totaltypescript.com/tsconfig-cheat-sheet<br /> > https://github.com/tsconfig/bases<br /> > https://www.typescriptlang.org/tsconfig/
<blockquote className="tip">
💡 &nbsp; Using TypeScript? Here are some links for reference

https://www.totaltypescript.com/tsconfig-cheat-sheet<br />
https://github.com/tsconfig/bases<br />
https://www.typescriptlang.org/tsconfig/

</blockquote>

<br />

<br />

Expand Down
11 changes: 8 additions & 3 deletions docs/how-tos/how-to-organize-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ Here's some recipes to show various patterns are possible.

<br />

> ℹ️ &nbsp; Note
>
> This way is preferred as it is better for code splitting.
<blockquote className="note">
ℹ️ &nbsp; Note

This way is preferred as it is better for code splitting.

</blockquote>

<br />

<br />

Expand Down
9 changes: 6 additions & 3 deletions docs/how-tos/how-to-reset-state.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ const reset = () => {

<br />

> ℹ️ &nbsp; Note
>
> Using `structuredClone()`
<blockquote className="note">
ℹ️ &nbsp; Note

Using `structuredClone()`

<br />

In 2022, there was a new global function added called `structuredClone` that is widely available in most modern browsers. You can use `structuredClone` in the same way as `deepClone` above, however `deepClone` is preferred as it will be aware of any `ref`s in your state.

</blockquote>
11 changes: 8 additions & 3 deletions docs/resources/libraries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ Valtio provides bare necessities for proxy state management which is great for m

<br />

> ⚠️ &nbsp; Warning
>
> Disclaimer: These libraries may have bugs, limited maintenance, or other limitations and are not officially recommended by pmndrs or the valtio maintainers. This list is to provide a good starting point for someone looking to extend valtio's feature set.
<blockquote className="warning">
⚠️ &nbsp; Warning

Disclaimer: These libraries may have bugs, limited maintenance, or other limitations and are not officially recommended by pmndrs or the valtio maintainers. This list is to provide a good starting point for someone looking to extend valtio's feature set.

</blockquote>

<br />

Expand All @@ -32,6 +35,8 @@ Valtio provides bare necessities for proxy state management which is great for m

- [valtio-persist](https://github.com/Noitidart/valtio-persist) - Flexible and performant saving of state to disk.

- [valtio-reactive](https://github.com/valtiojs/valtio-reactive) - Valtio-reactive makes valtio a reactive library.

- [valtio-signal](https://github.com/dai-shi/valtio-signal) - Another React binding for Valtio proxy state

- [valtio-yjs](https://github.com/dai-shi/valtio-yjs) - Valtio-yjs makes yjs state easy
Expand Down
49 changes: 47 additions & 2 deletions website/styles/prism-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,26 @@ pre[class*="language-"] {
}

/* Code blocks */
pre[class*="language-"] {
pre {
padding: 1em;
margin: 0.5em 0;
overflow: auto;
border-radius: 0.3em;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
code {
background: #2e3440;
padding: 0.1em;
}

code {
font-family: "Fira Code", Consolas, Monaco, "Andale Mono", "Ubuntu Mono",
monospace;
}

code::before, code::after {
content: '' !important;
}

/* Inline code */
Expand Down Expand Up @@ -123,3 +133,38 @@ pre[class*="language-"] {
.token.entity {
cursor: help;
}

blockquote.tip p::before,
blockquote.tip p::after,
blockquote.note p::before,
blockquote.note p::after,
blockquote.warning p::before,
blockquote.warning p::after,
blockquote.important p::before,
blockquote.important p::after {
content: '' !important;
}

blockquote {
padding-left: 1.5rem;
}

.tip {
border-left: 5px solid #88c0d0;
}

.note {
border-left: 5px solid #81a1c1;
}

.warning {
border-left: 5px solid #ebcb8b;
}

.important {
border-left: 5px solid #a3be8c;
}

code {

}

0 comments on commit 982a09f

Please sign in to comment.