本文整理汇总了TypeScript中src/common/github.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getCases
},
cases: []
},
reducers: {
setCases: (state: ICaseState, payload: ISetCase) => {
state.cases = payload.cases
state.meta = payload.meta
return state
}
},
effects: {
async getCases(payload: IGetCase) {
const { page, perPage } = payload.meta
try {
const { data, headers } = await github.get(`/repos/${CONFIG.owner}/showcase/issues`)
const link = headers.link
let newMeta = payload.meta
const cases: any[] = []
if (link) {
const isLast = link.match(/<([^>]+)>(?=\;\s+rel="last")/)
const lastPage = isLast ? isLast[1].match(/page=(\d+)/)[1] : page
newMeta = {
...payload.meta,
...{ page, per_page: perPage, total: lastPage * perPage }
}
}
data.forEach((c: any) => {
cases.push(dataParser(c))
})
dispatch.cases.setCases({ cases, meta: newMeta })
示例2: return
},
reducers: {
setGist: (state: IGistState, payload: any) => {
state.gist = payload
return state
},
setComments: (state: IGistState, payload: any[]) => {
return (state.comments = payload)
}
},
effects: {
async getGist(payload: string) {
try {
const { data } = await github.get(`/gists/${payload}`, {
headers: {
Accept: 'application/vnd.github.v3.html'
},
responseType: 'text'
})
for (const filename in data.files) {
if (data.files.hasOwnProperty(filename)) {
const file = data.files[filename]
const res = await github.post(
'/markdown',
{
text: '```' + file.language + '\n' + file.content + '\n```',
mode: 'markdown'
},
{ responseType: 'text' }
)
file.html = res.data
示例3: getPosts
posts: []
},
reducers: {
setPosts: (state: IPostState, payload: ISetPosts) => {
state.posts = payload.posts
state.meta = payload.meta
return state
}
},
effects: {
async getPosts(payload: IGetPosts) {
const { page, perPage } = payload.meta
try {
const res = await github.get(`/repos/${CONFIG.owner}/${CONFIG.repo}/issues`, {
params: { creator: CONFIG.owner, page, per_page: perPage, state: 'open' }
})
const posts = res.data
const link = res.headers.link
let newMeta = payload.meta
/**
* Pagination
* # see detail https://developer.github.com/guides/traversing-with-pagination/
*/
if (link) {
const isLast = link.match(/<([^>]+)>(?=\;\s+rel="last")/)
const lastPage = isLast ? isLast[1].match(/page=(\d+)/)[1] : page
newMeta = {
...payload.meta,
...{ page, per_page: perPage, total: lastPage * perPage }
}
示例4: return
reducers: {
setTodos: (state: ITodoState, payload: ISetTodos) => {
state.todos = payload.todos
state.meta = payload.meta
return state
},
setLabel: (state: ITodoState, payload: any[]) => {
return (state.labels = payload)
}
},
effects: {
async getTodos(payload: IGetTodos) {
const { page, perPage } = payload.meta
try {
const res = await github.get(`/repos/${CONFIG.owner}/${CONFIG.todo_repo}/issues`, {
params: { creator: CONFIG.owner, page, per_page: perPage, state: 'all' }
})
const todos = res.data
const link = res.headers.link
let newMeta = payload.meta
if (link) {
const isLast = link.match(/<([^>]+)>(?=\;\s+rel="last")/)
const lastPage = isLast ? isLast[1].match(/page=(\d+)/)[1] : page
newMeta = {
...payload.meta,
...{ page, per_page: perPage, total: lastPage * perPage }
}
}
dispatch.todos.setTodos({ todos, meta: newMeta })
} catch (err) {
console.error(err)
示例5: return
setRepo: (state: IRepoState, payload: any) => {
return (state.repo = payload)
},
setReadme: (state: IRepoState, payload: string) => {
return (state.readme = payload)
},
setEvents: (state: IRepoState, payload: any[]) => {
return (state.events = payload)
}
},
effects: {
async getRepo(payload: string) {
try {
const { data = {} } = await github.get(`/repos/${CONFIG.owner}/${payload}`, {
headers: {
Accept: 'application/vnd.github.mercy-preview+json;charset=utf-8'
}
})
dispatch.repo.getReadme(payload)
dispatch.repo.getEvents(payload)
dispatch.repo.setRepo(data)
} catch (err) {
console.error(err)
}
},
async getReadme(payload: string) {
try {
const { data } = await github.get(`/repos/${CONFIG.owner}/${payload}/readme`, {
headers: {
Accept: 'application/vnd.github.v3.html'
},
示例6: createModel
todo: any
}
const Todos = createModel({
state: {
todo: {}
},
reducers: {
setTodo: (state: ITodoState, payload: any) => {
return (state.todo = payload)
}
},
effects: {
async getTodo(payload: string) {
try {
const { data } = await github.get(`/repos/${CONFIG.owner}/${CONFIG.todo_repo}/issues/${payload}`, {
headers: {
Accept: 'application/vnd.github.v3.html'
},
responseType: 'text'
})
dispatch.todo.setTodo(data)
} catch (err) {
console.error(err)
}
}
}
})
export default Todos
示例7: getGists
gists: []
},
reducers: {
setGists: (state: IGistState, payload: ISetGists) => {
state.gists = payload.gists
state.meta = payload.meta
return state
}
},
effects: {
async getGists(payload: IGetGists) {
const { page, perPage } = payload.meta
try {
const res = await github.get(`/users/${CONFIG.owner}/gists`, {
params: { page, per_page: perPage }
})
const gists = res.data
const link = res.headers.link
let newMeta = payload.meta
if (link) {
const isLast = link.match(/<([^>]+)>(?=\;\s+rel="last")/)
const lastPage = isLast ? isLast[1].match(/page=(\d+)/)[1] : page
newMeta = {
...payload.meta,
...{ page, per_page: perPage, total: lastPage * perPage }
}
}
dispatch.gists.setGists({ gists, meta: newMeta })
} catch (err) {
console.error(err)
示例8: createModel
const About = createModel({
state: {
about: ''
},
reducers: {
storeAboutMe: (state: IAboutState, payload: ISetAbout) => {
return (state.about = payload.about)
}
},
effects: {
async getAboutMe() {
let html = ''
try {
const response = await github.get(`/repos/${CONFIG.owner}/${CONFIG.repo}/contents/ABOUTME.md`, {
headers: {
Accept: 'application/vnd.github.v3.html'
},
responseType: 'text'
})
html = response.data
} catch (err) {
console.error(err)
}
dispatch.about.storeAboutMe(html)
}
}
})
export default About
示例9: getRepos
},
reducers: {
setRepos: (state: IRepoState, payload: ISetRepos) => {
state.repos = payload.repos
state.meta = payload.meta
return state
}
},
effects: {
async getRepos(payload: IGetRepos) {
const { page, perPage } = payload.meta
try {
const res = await github.get(`/users/${CONFIG.owner}/repos?sort=created`, {
params: { page, per_page: perPage },
headers: {
Accept: 'application/vnd.github.mercy-preview+json;charset=utf-8'
}
})
const repos = res.data
const link = res.headers.link
let newMeta = payload.meta
/**
* Pagination
* # see detail https://developer.github.com/guides/traversing-with-pagination/
*/
if (link) {
const isLast = link.match(/<([^>]+)>(?=\;\s+rel="last")/)
const lastPage = isLast ? isLast[1].match(/page=(\d+)/)[1] : page
newMeta = {
...payload.meta,
...{ page, per_page: perPage, total: lastPage * perPage }