Skip to content

Commit

Permalink
refactor: revisit prettier config to be minimal (#816)
Browse files Browse the repository at this point in the history
* update config

* update snapshot
  • Loading branch information
Aslemammad authored Nov 13, 2023
1 parent a39759a commit d1e462e
Show file tree
Hide file tree
Showing 36 changed files with 172 additions and 166 deletions.
2 changes: 1 addition & 1 deletion docs/api/advanced/subscribe.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const state = proxy({ count: 0 })

// Subscribe to all changes to the state proxy (and its child proxies)
const unsubscribe = subscribe(state, () =>
console.log('state has changed to', state)
console.log('state has changed to', state),
)
// Unsubscribe by calling the result
unsubscribe()
Expand Down
3 changes: 2 additions & 1 deletion docs/api/basic/useSnapshot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ function Counter() {
if (state.count < 10) {
++state.count
}
}}>
}}
>
+1
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/api/utils/derive.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ derive(
},
{
proxy: state,
}
},
)
```

Expand Down
2 changes: 1 addition & 1 deletion docs/api/utils/subscribeKey.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { subscribeKey } from 'valtio/utils'

const state = proxy({ count: 0, text: 'hello' })
subscribeKey(state, 'count', (v) =>
console.log('state.count has changed to', v)
console.log('state.count has changed to', v),
)
```

Expand Down
2 changes: 1 addition & 1 deletion docs/how-tos/how-to-avoid-rerenders-manually.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Component = () => {
setCount(state.count)
}
}),
[]
[],
)
return <>{count}</>
}
Expand Down
2 changes: 1 addition & 1 deletion docs/how-tos/how-to-persist-states.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const state = proxy(
JSON.parse(localStorage.getItem('foo')) || {
count: 0,
text: 'hello',
}
},
)

subscribe(state, () => {
Expand Down
2 changes: 1 addition & 1 deletion docs/how-tos/some-gotchas.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const ChildComponent = React.memo(
<div>
{title} - {description}
</div>
)
),
)

const ParentComponent = () => {
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@
},
"prettier": {
"semi": false,
"trailingComma": "es5",
"singleQuote": true,
"bracketSameLine": true,
"tabWidth": 2,
"printWidth": 80
"singleQuote": true
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ import { subscribe } from 'valtio'

// Subscribe to all state changes
const unsubscribe = subscribe(state, () =>
console.log('state has changed to', state)
console.log('state has changed to', state),
)
// Unsubscribe by calling the result
unsubscribe()
Expand All @@ -146,7 +146,7 @@ import { subscribeKey } from 'valtio/utils'

const state = proxy({ count: 0, text: 'hello' })
subscribeKey(state, 'count', (v) =>
console.log('state.count has changed to', v)
console.log('state.count has changed to', v),
)
```
Expand Down
2 changes: 1 addition & 1 deletion src/macro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const macro = ({ references }: any) => {
path.parentPath?.parentPath?.replaceWith(
t.variableDeclaration('const', [
t.variableDeclarator(snap, t.callExpression(hook, [proxy])),
])
]),
)
let inFunction = 0
path.parentPath?.getFunctionParent()?.traverse({
Expand Down
2 changes: 1 addition & 1 deletion src/macro/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const valtioMacro = defineMacro(`useProxy`)
path.parentPath?.replaceWith(
t.variableDeclaration('const', [
t.variableDeclarator(snap, t.callExpression(hook, [proxy])),
])
]),
)

let inFunction = 0
Expand Down
12 changes: 6 additions & 6 deletions src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const { useSyncExternalStore } = useSyncExternalStoreExports

const useAffectedDebugValue = (
state: object,
affected: WeakMap<object, unknown>
affected: WeakMap<object, unknown>,
) => {
const pathList = useRef<(string | number | symbol)[][]>()
useEffect(() => {
Expand Down Expand Up @@ -117,7 +117,7 @@ type Options = {
*/
export function useSnapshot<T extends object>(
proxyObject: T,
options?: Options
options?: Options,
): Snapshot<T> {
const notifyInSync = options?.sync
const lastSnapshot = useRef<Snapshot<T>>()
Expand All @@ -130,7 +130,7 @@ export function useSnapshot<T extends object>(
callback() // Note: do we really need this?
return unsub
},
[proxyObject, notifyInSync]
[proxyObject, notifyInSync],
),
() => {
const nextSnapshot = snapshot(proxyObject, use)
Expand All @@ -143,7 +143,7 @@ export function useSnapshot<T extends object>(
lastSnapshot.current,
nextSnapshot,
lastAffected.current,
new WeakMap()
new WeakMap(),
)
) {
// not changed
Expand All @@ -154,7 +154,7 @@ export function useSnapshot<T extends object>(
}
return nextSnapshot
},
() => snapshot(proxyObject, use)
() => snapshot(proxyObject, use),
)
inRender = false
const currAffected = new WeakMap()
Expand All @@ -171,6 +171,6 @@ export function useSnapshot<T extends object>(
currSnapshot,
currAffected,
proxyCache,
targetCache
targetCache,
)
}
2 changes: 1 addition & 1 deletion src/react/utils/useProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useSnapshot } from '../../react.ts'
*/
export function useProxy<T extends object>(
proxy: T,
options?: NonNullable<Parameters<typeof useSnapshot>[1]>
options?: NonNullable<Parameters<typeof useSnapshot>[1]>,
): T {
const snapshot = useSnapshot(proxy, options) as T

Expand Down
22 changes: 11 additions & 11 deletions src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type HandlePromise = <P extends Promise<any>>(promise: P) => Awaited<P>
type CreateSnapshot = <T extends object>(
target: T,
version: number,
handlePromise?: HandlePromise
handlePromise?: HandlePromise,
) => T

type RemoveListener = () => void
Expand Down Expand Up @@ -91,7 +91,7 @@ const buildProxyFunction = (
status?: 'pending' | 'fulfilled' | 'rejected'
value?: Awaited<P>
reason?: unknown
}
},
) => {
switch (promise.status) {
case 'fulfilled':
Expand All @@ -108,7 +108,7 @@ const buildProxyFunction = (
createSnapshot: CreateSnapshot = <T extends object>(
target: T,
version: number,
handlePromise: HandlePromise = defaultHandlePromise
handlePromise: HandlePromise = defaultHandlePromise,
): T => {
const cache = snapCache.get(target)
if (cache?.[0] === version) {
Expand All @@ -127,7 +127,7 @@ const buildProxyFunction = (
const value = Reflect.get(target, key)
const { enumerable } = Reflect.getOwnPropertyDescriptor(
target,
key
key,
) as PropertyDescriptor
const desc: PropertyDescriptor = {
value,
Expand All @@ -143,12 +143,12 @@ const buildProxyFunction = (
desc.get = () => handlePromise(value)
} else if (proxyStateMap.has(value as object)) {
const [target, ensureVersion] = proxyStateMap.get(
value as object
value as object,
) as ProxyState
desc.value = createSnapshot(
target,
ensureVersion(),
handlePromise
handlePromise,
) as Snapshot<T>
}
Object.defineProperty(snap, key, desc)
Expand Down Expand Up @@ -202,7 +202,7 @@ const buildProxyFunction = (
>()
const addPropListener = (
prop: string | symbol,
propProxyState: ProxyState
propProxyState: ProxyState,
) => {
if (import.meta.env?.MODE !== 'production' && propProxyStates.has(prop)) {
throw new Error('prop listener already exists')
Expand Down Expand Up @@ -313,7 +313,7 @@ const buildProxyFunction = (
Reflect.ownKeys(initialObject).forEach((key) => {
const desc = Object.getOwnPropertyDescriptor(
initialObject,
key
key,
) as PropertyDescriptor
if ('value' in desc) {
proxyObject[key as keyof T] = initialObject[key as keyof T]
Expand All @@ -325,7 +325,7 @@ const buildProxyFunction = (
Object.defineProperty(baseObject, key, desc)
})
return proxyObject
}
},
) =>
[
// public functions
Expand Down Expand Up @@ -358,7 +358,7 @@ export function getVersion(proxyObject: unknown): number | undefined {
export function subscribe<T extends object>(
proxyObject: T,
callback: (ops: Op[]) => void,
notifyInSync?: boolean
notifyInSync?: boolean,
): () => void {
const proxyState = proxyStateMap.get(proxyObject as object)
if (import.meta.env?.MODE !== 'production' && !proxyState) {
Expand Down Expand Up @@ -393,7 +393,7 @@ export function subscribe<T extends object>(

export function snapshot<T extends object>(
proxyObject: T,
handlePromise?: HandlePromise
handlePromise?: HandlePromise,
): Snapshot<T> {
const proxyState = proxyStateMap.get(proxyObject as object)
if (import.meta.env?.MODE !== 'production' && !proxyState) {
Expand Down
4 changes: 2 additions & 2 deletions src/vanilla/utils/addComputed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export function addComputed_DEPRECATED<T extends object, U extends object>(
computedFns_FAKE: {
[K in keyof U]: (snap_FAKE: T) => U[K]
},
targetObject: any = proxyObject
targetObject: any = proxyObject,
) {
if (import.meta.env?.MODE !== 'production') {
console.warn(
'addComputed is deprecated. Please consider using `derive`. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201'
'addComputed is deprecated. Please consider using `derive`. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201',
)
}
const derivedFns: {
Expand Down
14 changes: 7 additions & 7 deletions src/vanilla/utils/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ type Options = {

export function devtools<T extends object>(
proxyObject: T,
options?: Options
options?: Options,
): (() => void) | undefined

/**
* @deprecated Please use { name } option
*/
export function devtools<T extends object>(
proxyObject: T,
name?: string
name?: string,
): (() => void) | undefined

/**
Expand All @@ -47,11 +47,11 @@ export function devtools<T extends object>(
*/
export function devtools<T extends object>(
proxyObject: T,
options?: Options | string
options?: Options | string,
) {
if (typeof options === 'string') {
console.warn(
'string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400'
'string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400',
)
options = { name: options }
}
Expand Down Expand Up @@ -94,15 +94,15 @@ export function devtools<T extends object>(
type: action,
updatedAt: new Date().toLocaleString(),
} as any,
snapWithoutDevtools
snapWithoutDevtools,
)
}
})
const unsub2 = (
devtools as unknown as {
// FIXME https://github.com/reduxjs/redux-devtools/issues/1097
subscribe: (
listener: (message: Message) => void
listener: (message: Message) => void,
) => (() => void) | undefined
}
).subscribe((message) => {
Expand All @@ -112,7 +112,7 @@ export function devtools<T extends object>(
} catch (e) {
console.error(
'please dispatch a serializable value that JSON.parse() and proxy() support\n',
e
e,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vanilla/utils/proxyMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type InternalProxyMap<K, V> = Map<K, V> & {
* state.get(key) //undefined
*/
export function proxyMap<K, V>(
entries?: Iterable<readonly [K, V]> | null
entries?: Iterable<readonly [K, V]> | null,
): Map<K, V> {
const map: InternalProxyMap<K, V> = proxy({
data: Array.from(entries || []) as KeyValRecord<K, V>[],
Expand Down
4 changes: 2 additions & 2 deletions src/vanilla/utils/proxyWithComputed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export function proxyWithComputed_DEPRECATED<
get: (snap: Snapshot<T>) => U[K]
set?: (state: T, newValue: U[K]) => void
}
}
},
) {
if (import.meta.env?.MODE !== 'production') {
console.warn(
'proxyWithComputed is deprecated. Please follow "Computed Properties" guide in docs.'
'proxyWithComputed is deprecated. Please follow "Computed Properties" guide in docs.',
)
}
;(Object.keys(computedFns) as (keyof U)[]).forEach((key) => {
Expand Down
6 changes: 3 additions & 3 deletions src/vanilla/utils/proxyWithHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function proxyWithHistory<V>(initialValue: V, skipSubscribe = false) {
undo: () => {
if (proxyObject.canUndo()) {
proxyObject.value = (proxyObject.history.wip = proxyObject.clone(
proxyObject.history.snapshots[--proxyObject.history.index]
proxyObject.history.snapshots[--proxyObject.history.index],
) as Snapshot<V>) as V
}
},
Expand All @@ -76,7 +76,7 @@ export function proxyWithHistory<V>(initialValue: V, skipSubscribe = false) {
redo: () => {
if (proxyObject.canRedo()) {
proxyObject.value = (proxyObject.history.wip = proxyObject.clone(
proxyObject.history.snapshots[++proxyObject.history.index]
proxyObject.history.snapshots[++proxyObject.history.index],
) as Snapshot<V>) as V
}
},
Expand All @@ -91,7 +91,7 @@ export function proxyWithHistory<V>(initialValue: V, skipSubscribe = false) {
ops.every(
(op) =>
op[1][0] === 'value' &&
(op[0] !== 'set' || op[2] !== proxyObject.history.wip)
(op[0] !== 'set' || op[2] !== proxyObject.history.wip),
)
) {
proxyObject.saveHistory()
Expand Down
Loading

1 comment on commit d1e462e

@vercel
Copy link

@vercel vercel bot commented on d1e462e Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

valtio – ./

valtio.vercel.app
valtio.pmnd.rs
valtio-pmndrs.vercel.app
valtio-git-main-pmndrs.vercel.app

Please sign in to comment.