Skip to content

Commit

Permalink
feat(utils): separate derive-valtio
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Oct 23, 2023
1 parent ee74322 commit 6889bb7
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 322 deletions.
10 changes: 8 additions & 2 deletions docs/api/utils/derive.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ description: 'create a new proxy derived from others'

# derive

## Installation

```bash
npm install derive-valtio
```

#### create a new proxy derived from others

You can subscribe to some proxies using `get` to create snapshots used to compute new values.

```js
import { derive } from 'valtio/utils'
import { derive } from 'derive-valtio'

// create a base proxy
const state = proxy({
Expand Down Expand Up @@ -43,7 +49,7 @@ In some cases you may want to unsubscribe after deriving a proxy. To do so, use
and you can attach new derived properties.

```js
import { derive, underive } from 'valtio/utils'
import { derive, underive } from 'derive-valtio'
const state = proxy({
count: 1,
})
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"homepage": "https://github.com/pmndrs/valtio",
"dependencies": {
"proxy-compare": "2.5.1",
"derive-valtio": "0.1.0",
"use-sync-external-store": "1.2.0"
},
"devDependencies": {
Expand Down
6 changes: 1 addition & 5 deletions src/vanilla/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
export { subscribeKey } from './utils/subscribeKey.ts'
export { watch } from './utils/watch.ts'
export { devtools } from './utils/devtools.ts'
export {
derive,
underive,
unstable_deriveSubscriptions,
} from './utils/derive.ts'
export { derive, underive, unstable_deriveSubscriptions } from 'derive-valtio'
export { addComputed_DEPRECATED as addComputed } from './utils/addComputed.ts'
export { proxyWithComputed_DEPRECATED as proxyWithComputed } from './utils/proxyWithComputed.ts'
export { proxyWithHistory } from './utils/proxyWithHistory.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/vanilla/utils/addComputed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { derive } from './derive.ts'
import { derive } from 'derive-valtio'

/**
* addComputed (DEPRECATED)
Expand Down
312 changes: 0 additions & 312 deletions src/vanilla/utils/derive.ts

This file was deleted.

5 changes: 3 additions & 2 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import path from 'path'
// eslint-disable-next-line import/extensions
import { defineConfig } from 'vitest/config'

export default defineConfig({
resolve: {
alias: [
{ find: /^valtio$/, replacement: './src/index.ts' },
{ find: /^valtio(.*)$/, replacement: './src/$1.ts' },
{ find: /^valtio$/, replacement: path.resolve('./src/index.ts') },
{ find: /^valtio(.*)$/, replacement: path.resolve('./src/$1.ts') },
],
},
test: {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2465,6 +2465,11 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==

derive-valtio@0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/derive-valtio/-/derive-valtio-0.1.0.tgz#4b9fb393dfefccfef15fcbbddd745dd22d5d63d7"
integrity sha512-OCg2UsLbXK7GmmpzMXhYkdO64vhJ1ROUUGaTFyHjVwEdMEcTTRj7W1TxLbSBxdY8QLBPCcp66MTyaSy0RpO17A==

diff-sequences@^29.4.3:
version "29.6.3"
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-29.6.3.tgz#4deaf894d11407c51efc8418012f9e70b84ea921"
Expand Down

0 comments on commit 6889bb7

Please sign in to comment.