Skip to content

Commit

Permalink
fix review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFlashAccount committed Mar 18, 2024
1 parent b0b4436 commit 2db1f06
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ export const BINDINGS = inputBindings.defineBindings({
},
goBack: {
name: 'Go Back',
bindings: ['Mod+ArrowLeft', 'Mod+['],
bindings: detect.isOnMacOS() ? ['Mod+ArrowLeft', 'Mod+['] : ['Alt+ArrowLeft', 'Alt+['],
rebindable: true,
icon: ArrowLeftIcon,
},
goForward: {
name: 'Go Forward',
bindings: ['Mod+ArrowRight', 'Mod+]'],
bindings: detect.isOnMacOS() ? ['Mod+ArrowRight', 'Mod+]'] : ['Alt+ArrowRight', 'Alt+]'],
rebindable: true,
icon: ArrowRightIcon,
},
Expand Down
19 changes: 8 additions & 11 deletions app/ide-desktop/lib/dashboard/src/hooks/eventCallback.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
/**
* @file useEventCallback shim from the latest React RFC.
* @file useEventCallback shim
*/

/* eslint-disable @typescript-eslint/no-explicit-any */
import * as React from 'react'

import * as syncRef from './syncRef'

/**
* useEventCallback shim from the latest React RFC.
* useEvent shim.
* @see https://github.com/reactjs/rfcs/pull/220
* @see https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md#internal-implementation
*/
export function useEventCallback<
Func extends (...args: Args) => Result,
Args extends Parameters<any> = Parameters<Func>,
Result extends ReturnType<any> = ReturnType<Func>,
>(callback: Func): (...args: Args) => Result {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useEventCallback<Func extends (...args: any[]) => unknown>(callback: Func) {
const callbackRef = syncRef.useSyncRef(callback)

// make sure that the value of `this` provided for the call to fn is not `ref`
// eslint-disable-next-line no-restricted-syntax
return React.useCallback((...args) => callbackRef.current.apply(void 0, args), [])
// Make sure that the value of `this` provided for the call to fn is not `ref`
// This type assertion is safe, because it's a transparent wrapper around the original callback
// eslint-disable-next-line react-hooks/exhaustive-deps, no-restricted-syntax
return React.useCallback(((...args) => callbackRef.current.apply(void 0, args)) as Func, [])
}
5 changes: 4 additions & 1 deletion app/ide-desktop/lib/dashboard/src/hooks/useLazyMemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import * as React from 'react'

const UNSET_VALUE = Symbol('inset')
const UNSET_VALUE = Symbol('unset')

/**
* A hook that returns a memoized function that will only be called once
Expand All @@ -22,5 +22,8 @@ export function useLazyMemo<T>(factory: T | (() => T), deps: React.DependencyLis

return cachedValue
}
// We assume that the callback should change only when
// the deps change.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps)
}
10 changes: 2 additions & 8 deletions app/ide-desktop/lib/dashboard/src/utilities/safeJsonParse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@
export function safeJsonParse<T = unknown>(
value: string,
defaultValue: T,
assert: (parsed: unknown) => parsed is T
predicate: (parsed: unknown) => parsed is T
): T {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
const parsed: unknown = JSON.parse(value)

if (assert(parsed)) {
return parsed
} else {
return defaultValue
}
return predicate(parsed) ? parsed : defaultValue
} catch {
return defaultValue
}
Expand Down

0 comments on commit 2db1f06

Please sign in to comment.