Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor major components to streamline logic #1589

Merged
merged 17 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Comment on lines +1 to +15
Copy link
Member

Choose a reason for hiding this comment

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

💭 OOF, I have bad feelings about maintaining this long term.

@Gozala thoughts on how feasible it is to pick HenrikJoreteg/redux-bundler#69 up and add those types to the upstream package (with GitHub action that tests them there)?

Copy link
Contributor Author

@Gozala Gozala Sep 17, 2020

Choose a reason for hiding this comment

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

I don't believe it is worth it honestly. Because it is not really possible to add proper typings to the redux-bundler. What I do here is just provide some subset which also requires very particular use of redux-bundler (splitting actions and selectors, which seems to go against it's design goals), and even then have to manually annotate. Given these limitations, I doubt it would be accepted, I also don't think the effort to do that is going to pay off.

If we were to invest more time into this, I would rather consider using redux-bundler alternatives that would be more type friendly / ready than redux-bundler is.


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