mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: expose props when get
This commit is contained in:
parent
db23b69d7f
commit
8141dfa3b4
3 changed files with 11 additions and 13 deletions
|
|
@ -31,7 +31,7 @@ function run<M extends Method>([method, args]: [M, Parameters<M>]) {
|
|||
}
|
||||
|
||||
export type DispatchState<Props, State> = React.Component<Props, State>['setState']
|
||||
export type GetState<State> = () => State
|
||||
export type GetState<Props, State> = () => [State, Props]
|
||||
export type TriggerOtherMethod<Props, State> = <Args extends any[]>(
|
||||
methodCreator: MethodCreator<Props, State, Args>,
|
||||
...args: Parameters<ReturnType<MethodCreator<Props, State, Args>>>
|
||||
|
|
@ -39,7 +39,7 @@ export type TriggerOtherMethod<Props, State> = <Args extends any[]>(
|
|||
|
||||
export type Dispatch<Props, State> = {
|
||||
set: DispatchState<Props, State>
|
||||
get: GetState<State>
|
||||
get: GetState<Props, State>
|
||||
call: TriggerOtherMethod<Props, State>
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ function link<P, S>(instance: React.Component<P, S>, sources: Sources<P, S>): Wr
|
|||
const dispatchState: DispatchState<P, S> = (updater, callback) => {
|
||||
instance.setState(updater, callback)
|
||||
}
|
||||
const prepareState: GetState<S> = () => instance.state
|
||||
const prepareState: GetState<P, S> = () => [instance.state, instance.props]
|
||||
const dispatch: Dispatch<P, S> = {
|
||||
call: dispatchCall,
|
||||
get: prepareState,
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ export const setStateText: BoundMethodCreator<[ConnectorState['stateText']]> = d
|
|||
})
|
||||
|
||||
export const handleKeyDown: BoundMethodCreator<[React.KeyboardEvent]> = dispatch => event => {
|
||||
const { searched, visibleNodes } = dispatch.get()
|
||||
const [{ searched, visibleNodes }] = dispatch.get()
|
||||
if (!visibleNodes) return
|
||||
const { nodes, focusedNode, expandedNodes, depths } = visibleNodes
|
||||
function handleVerticalMove(index: number) {
|
||||
|
|
@ -327,9 +327,8 @@ export const toggleNodeExpansion: BoundMethodCreator<[TreeNode, boolean]> = disp
|
|||
|
||||
export const focusNode: BoundMethodCreator<[TreeNode | null, boolean]> = dispatch => (
|
||||
node: TreeNode | null,
|
||||
skipScroll = false,
|
||||
) => {
|
||||
const { visibleNodes } = dispatch.get()
|
||||
const [{ visibleNodes }] = dispatch.get()
|
||||
if (!visibleNodes) return
|
||||
visibleNodesGenerator.focusNode(node)
|
||||
dispatch.call(updateVisibleNodes)
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ export type ConnectorState = {
|
|||
type BoundMethodCreator<Args extends any[] = []> = MethodCreator<Props, ConnectorState, Args>
|
||||
|
||||
export const init: BoundMethodCreator = dispatch => async () => {
|
||||
const { initializingPromise } = dispatch.get()
|
||||
const [{ initializingPromise }] = dispatch.get()
|
||||
if (initializingPromise) await initializingPromise
|
||||
|
||||
let done: any = null // cannot use type `(() => void) | null` here
|
||||
|
|
@ -175,7 +175,7 @@ export const handleError: BoundMethodCreator<[Error]> = dispatch => async err =>
|
|||
}
|
||||
|
||||
export const onPJAXEnd: BoundMethodCreator = dispatch => () => {
|
||||
const { metaData, copyFileButton, copySnippetButton, intelligentToggle } = dispatch.get()
|
||||
const [{ metaData, copyFileButton, copySnippetButton, intelligentToggle }] = dispatch.get()
|
||||
DOMHelper.unmountTopProgressBar()
|
||||
DOMHelper.decorateGitHubPageContent({ copyFileButton, copySnippetButton })
|
||||
const mergedMetaData = { ...metaData, ...URLHelper.parse() }
|
||||
|
|
@ -187,7 +187,7 @@ export const onPJAXEnd: BoundMethodCreator = dispatch => () => {
|
|||
}
|
||||
|
||||
export const onKeyDown: BoundMethodCreator<[KeyboardEvent]> = dispatch => e => {
|
||||
const { toggleShowSideBarShortcut } = dispatch.get()
|
||||
const [{ toggleShowSideBarShortcut }] = dispatch.get()
|
||||
if (toggleShowSideBarShortcut) {
|
||||
const keys = keyHelper.parseEvent(e)
|
||||
if (keys === toggleShowSideBarShortcut) {
|
||||
|
|
@ -197,9 +197,8 @@ export const onKeyDown: BoundMethodCreator<[KeyboardEvent]> = dispatch => e => {
|
|||
}
|
||||
|
||||
export const toggleShowSideBar: BoundMethodCreator = dispatch => () => {
|
||||
const { intelligentToggle } = dispatch.get()
|
||||
const shouldShow = !dispatch.get().shouldShow
|
||||
dispatch.call(setShouldShow, shouldShow)
|
||||
const [{ intelligentToggle, shouldShow }] = dispatch.get()
|
||||
dispatch.call(setShouldShow, !shouldShow)
|
||||
|
||||
if (intelligentToggle !== null) {
|
||||
dispatch.call(setIntelligentToggle, shouldShow)
|
||||
|
|
@ -267,7 +266,7 @@ export const useListeners: BoundMethodCreator<[boolean]> = dispatch => {
|
|||
const $onPJAXEnd = () => dispatch.call(onPJAXEnd)
|
||||
const $onKeyDown = (e: KeyboardEvent) => dispatch.call(onKeyDown, e)
|
||||
return on => {
|
||||
const { disabled } = dispatch.get()
|
||||
const [{ disabled }] = dispatch.get()
|
||||
if (on && !disabled) {
|
||||
window.addEventListener('pjax:complete', $onPJAXEnd)
|
||||
window.addEventListener('keydown', $onKeyDown)
|
||||
|
|
|
|||
Loading…
Reference in a new issue