Skip to content

Commit 2331304

Browse files
author
kenberkeley
committed
git case sensitive
1 parent 3746993 commit 2331304

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/services/xhr/superagent.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import request from 'superagent'
2+
import { rootPath, errHandler } from './config'
3+
4+
const xhr = ({ url, body = null, method = 'get' }) => {
5+
// P.S: 此处引入了ES6的Promise实现
6+
return new Promise((resolve, reject) => {
7+
request[method.toLowerCase()](rootPath + url)
8+
.send(body)
9+
// .withCredentials()
10+
.end((err, re) => {
11+
if (err)
12+
return errHandler(err)
13+
14+
if (!re.body)
15+
return resolve(null)
16+
17+
if (re.body._code)
18+
return errHandler(re.body._msg)
19+
20+
resolve(re.body)
21+
})
22+
})
23+
}
24+
25+
export default xhr

src/utils/HoC/ExampleHoC.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { Component } from 'react'
2+
3+
/* 高阶组件 High Order Component 例子 */
4+
const ExampleHoC = WrappedComponent => class extends Component {
5+
componentWillMount() {
6+
console.info('[HoC] componentWillMount')
7+
}
8+
9+
componentDidMount() {
10+
console.info('[HoC] componentDidMount')
11+
}
12+
13+
render () {
14+
return <WrappedComponent {...this.props} />
15+
}
16+
}
17+
18+
export default ExampleHoC
19+
20+
/**
21+
*【拓展】
22+
* React Router 2.4 新增 withRouter 这个 HoC
23+
* 这是除 context 外另一种获取 router 的推荐方式
24+
* https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.4.0.md
25+
*
26+
* 本项目中的 Redirect 组件用到了该高阶组件
27+
*/

0 commit comments

Comments
 (0)