mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
build: upgrade typescript
This commit is contained in:
parent
b9380f2cc3
commit
a2b640b31e
7 changed files with 353 additions and 350 deletions
|
|
@ -53,7 +53,7 @@
|
|||
"less": "^3.9.0",
|
||||
"less-loader": "^4.0.5",
|
||||
"style-loader": "^0.23.1",
|
||||
"typescript": "3.3",
|
||||
"typescript": "^3.6.3",
|
||||
"uglifyjs-webpack-plugin": "^2.1.2",
|
||||
"url-loader": "^1.1.2",
|
||||
"webpack": "^4.29.6",
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
import * as React from 'react'
|
||||
import { raiseError } from 'analytics'
|
||||
|
||||
export type Method<Args = any[]> = (
|
||||
...args: Args extends any[] ? Args : any[]
|
||||
) => void | Promise<void>
|
||||
export type Method<Args extends any[] = any[]> = (...args: Args) => void | Promise<void>
|
||||
export type Middleware = <M extends Method, MM extends Method>(
|
||||
method: M,
|
||||
args: Parameters<M>,
|
||||
|
|
@ -35,9 +32,9 @@ 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 TriggerOtherMethod<Props, State> = <Args, MC extends MethodCreator<Props, State, Args>>(
|
||||
methodCreator: MC,
|
||||
...args: Parameters<ReturnType<MC>>
|
||||
export type TriggerOtherMethod<Props, State> = <Args extends any[]>(
|
||||
methodCreator: MethodCreator<Props, State, Args>,
|
||||
...args: Parameters<ReturnType<MethodCreator<Props, State, Args>>>
|
||||
) => void
|
||||
|
||||
export type Dispatch<Props, State> = {
|
||||
|
|
@ -46,7 +43,7 @@ export type Dispatch<Props, State> = {
|
|||
call: TriggerOtherMethod<Props, State>
|
||||
}
|
||||
|
||||
export type MethodCreator<Props, State, Args = []> = (
|
||||
export type MethodCreator<Props, State, Args extends any[] = []> = (
|
||||
dispatch: Dispatch<Props, State>,
|
||||
) => Method<Args>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import { raiseError } from 'analytics'
|
||||
import { Props } from 'components/FileExplorer'
|
||||
import { GetCreatedMethod, MethodCreator } from 'driver/connect'
|
||||
import * as ini from 'ini'
|
||||
import { Base64 } from 'js-base64'
|
||||
import DOMHelper from 'utils/DOMHelper'
|
||||
import { findNode } from 'utils/general'
|
||||
import GitHubHelper, { BlobData } from 'utils/GitHubHelper'
|
||||
import treeParser from 'utils/treeParser'
|
||||
import URLHelper from 'utils/URLHelper'
|
||||
import VisibleNodesGenerator, { TreeNode, VisibleNodes } from 'utils/VisibleNodesGenerator'
|
||||
import GitHubHelper, { BlobData } from 'utils/GitHubHelper'
|
||||
import { findNode } from 'utils/general'
|
||||
import { MethodCreator, GetCreatedMethod } from 'driver/connect'
|
||||
import { Props } from 'components/FileExplorer'
|
||||
import { raiseError } from 'analytics'
|
||||
|
||||
export type ConnectorState = {
|
||||
stateText: string
|
||||
|
|
@ -48,7 +48,7 @@ type Task = () => void
|
|||
const tasksAfterRender: (Task)[] = []
|
||||
let visibleNodesGenerator: VisibleNodesGenerator
|
||||
|
||||
type BoundMethodCreator<Args = []> = MethodCreator<Props, ConnectorState, Args>
|
||||
type BoundMethodCreator<Args extends any[] = []> = MethodCreator<Props, ConnectorState, Args>
|
||||
|
||||
const init: BoundMethodCreator = dispatch => () =>
|
||||
dispatch.call(setStateText, 'Fetching File List...')
|
||||
|
|
|
|||
|
|
@ -1,22 +1,20 @@
|
|||
import { Props } from 'components/SideBar'
|
||||
import { GetCreatedMethod, MethodCreator } from 'driver/connect'
|
||||
import configHelper, { Config } from 'utils/configHelper'
|
||||
import DOMHelper from 'utils/DOMHelper'
|
||||
import GitHubHelper, {
|
||||
NOT_FOUND,
|
||||
BAD_CREDENTIALS,
|
||||
API_RATE_LIMIT,
|
||||
BAD_CREDENTIALS,
|
||||
BLOCKED_PROJECT,
|
||||
EMPTY_PROJECT,
|
||||
MetaData,
|
||||
NOT_FOUND,
|
||||
TreeData,
|
||||
BLOCKED_PROJECT,
|
||||
} from 'utils/GitHubHelper'
|
||||
import configHelper from 'utils/configHelper'
|
||||
import URLHelper from 'utils/URLHelper'
|
||||
import keyHelper from 'utils/keyHelper'
|
||||
import { MethodCreator, GetCreatedMethod } from 'driver/connect'
|
||||
import { Props } from 'components/SideBar'
|
||||
import URLHelper from 'utils/URLHelper'
|
||||
|
||||
export type ConnectorState = {
|
||||
// initial width of side bar
|
||||
baseSize: number
|
||||
// error message
|
||||
error?: string
|
||||
// whether Gitako side bar should be shown
|
||||
|
|
@ -25,22 +23,14 @@ export type ConnectorState = {
|
|||
showSettings: boolean
|
||||
// whether failed loading the repo due to it is private
|
||||
errorDueToAuth: boolean
|
||||
// access token for GitHub
|
||||
accessToken?: string
|
||||
// the shortcut string for toggle sidebar
|
||||
toggleShowSideBarShortcut?: string
|
||||
// meta data for the repository
|
||||
metaData?: MetaData
|
||||
// file tree data
|
||||
treeData?: TreeData
|
||||
// few settings
|
||||
compressSingletonFolder: boolean
|
||||
copyFileButton: boolean
|
||||
copySnippetButton: boolean
|
||||
logoContainerElement: Element | null
|
||||
disabled: boolean
|
||||
initializingPromise: Promise<void> | null
|
||||
|
||||
} & {
|
||||
init: GetCreatedMethod<typeof init>
|
||||
onPJAXEnd: GetCreatedMethod<typeof onPJAXEnd>
|
||||
onKeyDown: GetCreatedMethod<typeof onKeyDown>
|
||||
|
|
@ -52,9 +42,16 @@ export type ConnectorState = {
|
|||
setCopyFile: GetCreatedMethod<typeof setCopyFile>
|
||||
setCopySnippet: GetCreatedMethod<typeof setCopySnippet>
|
||||
setCompressSingleton: GetCreatedMethod<typeof setCompressSingleton>
|
||||
}
|
||||
} & {
|
||||
baseSize: number
|
||||
toggleShowSideBarShortcut?: string
|
||||
accessToken?: string
|
||||
} & Pick<
|
||||
Config,
|
||||
'compressSingletonFolder' | 'copyFileButton' | 'copySnippetButton' | 'sideBarOpenStatus'
|
||||
>
|
||||
|
||||
type BoundMethodCreator<Args = []> = MethodCreator<Props, ConnectorState, Args>
|
||||
type BoundMethodCreator<Args extends any[] = []> = MethodCreator<Props, ConnectorState, Args>
|
||||
|
||||
const init: BoundMethodCreator = dispatch => async () => {
|
||||
const { initializingPromise } = dispatch.get()
|
||||
|
|
@ -251,8 +248,8 @@ const setCopySnippet: BoundMethodCreator<
|
|||
> = dispatch => copySnippetButton => dispatch.set({ copySnippetButton })
|
||||
|
||||
const useListeners: BoundMethodCreator<[boolean]> = dispatch => {
|
||||
const $onPJAXEnd = dispatch.call.bind(dispatch, onPJAXEnd)
|
||||
const $onKeyDown = dispatch.call.bind(dispatch, onKeyDown)
|
||||
const $onPJAXEnd = () => dispatch.call(onPJAXEnd)
|
||||
const $onKeyDown = (e: KeyboardEvent) => dispatch.call(onKeyDown, e)
|
||||
return on => {
|
||||
const { disabled } = dispatch.get()
|
||||
if (on && !disabled) {
|
||||
|
|
|
|||
5
src/global.d.ts
vendored
5
src/global.d.ts
vendored
|
|
@ -4,8 +4,3 @@ declare module '*.svg?svgr' {
|
|||
const component: SvgrComponent
|
||||
export default component
|
||||
}
|
||||
|
||||
type Omit<T, K extends keyof T> = Pick<
|
||||
T,
|
||||
({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never })[keyof T]
|
||||
>
|
||||
|
|
|
|||
|
|
@ -34,11 +34,7 @@ function applyDefaultConfigs(configs: Config) {
|
|||
return configKeyArray.reduce(
|
||||
(applied, configKey) => {
|
||||
const key = configKey as keyof Config
|
||||
if (!(key in configs)) {
|
||||
applied[key] = defaultConfigs[key]
|
||||
} else {
|
||||
applied[key] = configs[key]
|
||||
}
|
||||
Object.assign(applied, { [key]: key in configs ? configs[key] : defaultConfigs[key] })
|
||||
return applied
|
||||
},
|
||||
{} as Config,
|
||||
|
|
|
|||
Loading…
Reference in a new issue