Skip to content

Commit

Permalink
feat: refactor and type major components to streamline logic (#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala authored Sep 21, 2020
1 parent 0bb8bea commit 056d389
Show file tree
Hide file tree
Showing 22 changed files with 2,419 additions and 903 deletions.
23 changes: 21 additions & 2 deletions @types/ipfs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ declare module "ipfs" {
files: FileService
name: NameService
object: ObjectService
config: ConfigService

stop(options?: TimeoutOptions): Promise<void>
}

export interface CoreService {
Expand All @@ -31,6 +34,20 @@ declare module "ipfs" {
mkdir(path: string, options: FSMakDirectoryOptions): Promise<void>
}

export interface ConfigService {
get(key: string, options?: TimeoutOptions): Promise<Object>
getAll(options?: TimeoutOptions): Promise<Object>
set(key: string, value: string | number | null | boolean | Object, options?: TimeoutOptions): Promise<void>
replace(config: Object, options?: TimeoutOptions): Promise<void>

profiles: ConfigProfiles
}

export interface ConfigProfiles {
list(options?: TimeoutOptions): Promise<Array<{ name: string, description: string }>>
apply(name: string, options?: { dryRun?: boolean } & TimeoutOptions): Promise<{ original: Object, updated: Object }>
}

export interface NameService {
resolve(value: string, options?: NameResloveOptions): AsyncIterable<string>
}
Expand Down Expand Up @@ -128,7 +145,7 @@ declare module "ipfs" {

export type FileType =
| 'file'
| 'dir'
| 'directory'

export interface FileStat {
cid: CID
Expand Down Expand Up @@ -168,7 +185,9 @@ declare module "ipfs" {
path: string,
size: number,
cid: CID,
type: FileType,
// IPFS is pretty inconsistent with type field see
// https://github.com/ipfs/js-ipfs/issues/3229
type: FileType | 'dir',
mode: number,
mtime: { secs: number, nsecs?: number }
}
Expand Down
5 changes: 5 additions & 0 deletions @types/it-first/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "it-first" {
function first<T>(input: AsyncIterable<T>): Promise<T>

export default first
}
70 changes: 70 additions & 0 deletions @types/redux-bundler/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
declare module "redux-bundler" {

interface CreateSelector {
<State, I, O>(n1: string, f: (inn: I) => O): (state: State) => O,
<State, I1, I2, O>(n1: string, n2: string, f: (i1: I1, i2: I2) => O): (state: State) => O
<State, I1, I2, I3, O>(n1: string, n2: string, n3: string, f: (i1: I1, i2: I2, i3: I3) => O): (state: State) => O
<State, I1, I2, I3, I4, O>(n1: string, n2: string, n3: string, n4: string, f: (i1: I1, i2: I2, i3: I3, i4: I4) => O): (state: State) => O
<State, I1, I2, I3, I4, I5, O>(n1: string, n2: string, n3: string, n4: string, n5: string, f: (i1: I1, i2: I2, i3: I3, i4: I4, i5: I5) => O): (state: State) => O

<State, I1, O>(s1: (state: State) => I1, f: (inn: I1) => O): (state: State) => O,
<State, I1, I2, O>(s1: (state: State) => I1, s2: (state: State) => I2, f: (i1: I1, i2: I2) => O): (state: State) => O
<State, I1, I2, I3, O>(s1: (state: State) => I1, s2: (state: State) => I2, s3: (state: State) => I3, f: (i1: I1, i2: I2, i3: I3) => O): (state: State) => O
<State, I1, I2, I3, I4, O>(s1: (state: State) => I1, s2: (state: State) => I2, s3: (state: State) => I3, s4: (state: State) => I4, f: (i1: I1, i2: I2, i3: I3, i4: I4) => O): (state: State) => O
<State, I1, I2, I3, I4, I5, O>(s1: (state: State) => I1, s2: (state: State) => I2, s3: (state: State) => I3, s4: (state: State) => I4, s5: (state: State) => I5, f: (i1: I1, i2: I2, i3: I3, i4: I4, i5: I5) => O): (state: State) => O
}

declare export var createSelector: CreateSelector

export type Selector<State, Data> =
(state: State) => Data

type Action = { type: string }



export type BaseStore<State, Message extends Action> = {
getState(): State
dispatch(message: Message): void

destroy(): void
}

export type Store<State, Message extends Action, Ext = {}> = {
getState(): State
dispatch(message: Message): void
subscribeToSelectors(selectors: string[], callback: (any) => void | (() => void)): void

destroy(): void
} & Ext


export type Context<State, Message extends Action, Ext, Extra = {}> = {
getState(): State
dispatch(message: Message): void
store: Store<State, Message, Ext>
} & Extra

export type Reducer<State, Message> =
(state?: State, message: Message) => State

export type BundleInit<State, Messag extends Action, Ext = {}> =
(store: Store<State, Message, Ext>) => void | (() => void)

export type Bundle<State, Message extends Action, Ext = {}, Extra = never> = {
name: string
reducer?: Reducer<State, Message>
getReducer?: () => Reducer<State, Message>
}


export type Selectors<T> = {
[K in keyof T]: T[K] extends Selector<any, infer D>
? () => D
: never
}

export type Actions<T> = {
[K in keyof T]: (...args: ParamsType<T[K]>) => ReturnType<ReturnType<T[K]>>
}
}
6 changes: 3 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import FilesExploreForm from './files/explore-form/FilesExploreForm'

export class App extends Component {
static propTypes = {
doInitIpfs: PropTypes.func.isRequired,
doTryInitIpfs: PropTypes.func.isRequired,
doUpdateUrl: PropTypes.func.isRequired,
doUpdateHash: PropTypes.func.isRequired,
doFilesWrite: PropTypes.func.isRequired,
Expand All @@ -35,7 +35,7 @@ export class App extends Component {
}

componentDidMount () {
this.props.doInitIpfs()
this.props.doTryInitIpfs()
}

addFiles = async (filesPromise) => {
Expand Down Expand Up @@ -133,7 +133,7 @@ export default connect(
'doExploreUserProvidedPath',
'doUpdateUrl',
'doUpdateHash',
'doInitIpfs',
'doTryInitIpfs',
'doFilesWrite',
'doDisableTooltip',
'selectFilesPathInfo',
Expand Down
2 changes: 1 addition & 1 deletion src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ it.skip('renders without crashing', () => {
// const Page = () => 'test'

// shallow(null
// <App doInitIpfs={noop} doUpdateUrl={noop} route={Page} queryObject={{}} />
// <App doTryInitIpfs={noop} doUpdateUrl={noop} route={Page} queryObject={{}} />
// )
})
Loading

0 comments on commit 056d389

Please sign in to comment.