mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor: remove link
This commit is contained in:
parent
1de478a83d
commit
84d1859991
3 changed files with 30 additions and 25 deletions
|
|
@ -1,16 +1,43 @@
|
|||
import React from 'react'
|
||||
|
||||
export default function connect(core) {
|
||||
function isObject(target) {
|
||||
return typeof target === 'object' && target !== null
|
||||
}
|
||||
|
||||
function link(instance, sources) {
|
||||
const wrappedMethods = {/* sources[key] -> wrappedMethods.method */}
|
||||
const map = new Map(/* sources.creator -> wrappedMethods.method */)
|
||||
|
||||
function dispatch(...args) {
|
||||
if (Object.values(sources).includes(args[0])) {
|
||||
map.get(args[0])(...args.slice(1))
|
||||
} else {
|
||||
setTimeout(
|
||||
instance.setState.bind(instance, ...args),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Object.entries(sources).forEach(([key, createMethod]) => {
|
||||
const method = createMethod(dispatch)
|
||||
wrappedMethods[key] = method
|
||||
map.set(createMethod, method)
|
||||
})
|
||||
|
||||
return wrappedMethods
|
||||
}
|
||||
|
||||
export default function connect(mapping) {
|
||||
return function linkComponent(ComponentClass) {
|
||||
return class AwesomeApp extends React.PureComponent {
|
||||
static displayName = `Driven${ComponentClass.name}`
|
||||
|
||||
state = {}
|
||||
boundCore = core(this)
|
||||
boundCore = link(this, mapping)
|
||||
|
||||
render() {
|
||||
return (
|
||||
<ComponentClass {...this.boundCore} {...this.state} />
|
||||
<ComponentClass {...this.props} {...this.boundCore} {...this.state}/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import link from './link'
|
||||
|
||||
import DOMHelper, { REPO_TYPE_PRIVATE } from '../utils/DOMHelper'
|
||||
import GitHubHelper, { NOT_FOUND, BAD_CREDENTIALS } from '../utils/GitHubHelper'
|
||||
import storageHelper from '../utils/storageHelper'
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
export default function link(setState, sources) {
|
||||
const wrappedMethods = {/* sources[key] -> wrappedMethods.method */}
|
||||
const map = new Map(/* sources.creator -> wrappedMethods.method */)
|
||||
|
||||
function dispatch(...args) {
|
||||
if (Object.values(sources).includes(args[0])) {
|
||||
map.get(args[0])(...args.slice(1))
|
||||
} else {
|
||||
setState(...args)
|
||||
}
|
||||
}
|
||||
|
||||
Object.entries(sources).forEach(([key, createMethod]) => {
|
||||
const method = createMethod(dispatch)
|
||||
wrappedMethods[key] = method
|
||||
map.set(createMethod, method)
|
||||
})
|
||||
|
||||
return wrappedMethods
|
||||
}
|
||||
Loading…
Reference in a new issue