• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript core.createModel函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@rematch/core.createModel函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createModel函数的具体用法?TypeScript createModel怎么用?TypeScript createModel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了createModel函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: createModel

const Gist = createModel({
  state: {
    gist: {},
    comments: []
  },
  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
          }
        }
        dispatch.gist.getComments(payload)
        dispatch.gist.setGist(data)
      } catch (err) {
        console.error(err)
      }
    },
    async getComments(payload: string) {
      try {
        const { data } = await github.get(`/gists/${payload}/comments`, {
          headers: {
            Accept: 'application/vnd.github.v3.html'
          },
          responseType: 'text'
        })

        dispatch.gist.setComments(data)
      } catch (err) {
        console.error(err)
      }
    }
  }
})
开发者ID:duhongjun,项目名称:blog,代码行数:60,代码来源:gist.ts


示例2: createModel

const Todos = createModel({
  state: {
    meta: {
      page: 1,
      perPage: 10,
      total: 0
    },
    todos: [],
    labels: []
  },
  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)
      }
    },
    async getLabels() {
      const { data } = await github.get(`/repos/${CONFIG.owner}/${CONFIG.todo_repo}/labels`)
      dispatch.todos.setLabel(data)
    }
  }
})
开发者ID:duhongjun,项目名称:blog,代码行数:49,代码来源:todos.ts


示例3: createModel

const Cases = createModel({
  state: {
    meta: {
      page: 1,
      perPage: 10,
      total: 0
    },
    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 })
      } catch (err) {
        console.error(err)
      }
    }
  }
})
开发者ID:duhongjun,项目名称:blog,代码行数:43,代码来源:cases.ts


示例4: createModel

const Repo = createModel({
  state: {
    repo: {},
    readme: '',
    events: []
  },
  reducers: {
    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'
          },
          responseType: 'text'
        })
        dispatch.repo.setReadme(data)
      } catch (err) {
        console.error(err)
      }
    },
    async getEvents(payload: string) {
      try {
        const { data } = await github.get(`/repos/${CONFIG.owner}/${payload}/events`)
        dispatch.repo.setEvents(data)
      } catch (err) {
        console.error(err)
      }
    }
  }
})
开发者ID:duhongjun,项目名称:blog,代码行数:55,代码来源:repo.ts


示例5: createModel

const Posts = createModel({
  state: {
    meta: {
      page: 1,
      perPage: 10,
      total: 0
    },
    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 }
          }
        }
        posts.forEach((post: any) => {
          // 获取第一张图片作为缩略图
          const match = /!\[[^\]]+\]\(([^\)]+)\)/im.exec(post.body)
          if (match && match[1]) {
            post.thumbnails = match[1]
          }
        })
        dispatch.posts.setPosts({ posts, meta: newMeta })
      } catch (err) {
        console.error(err)
      }
    }
  }
})
开发者ID:duhongjun,项目名称:blog,代码行数:53,代码来源:posts.ts


示例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
开发者ID:duhongjun,项目名称:blog,代码行数:30,代码来源:todo.ts


示例7: createModel

const Gists = createModel({
  state: {
    meta: {
      page: 1,
      perPage: 10,
      total: 0
    },
    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)
      }
    }
  }
})
开发者ID:duhongjun,项目名称:blog,代码行数:42,代码来源:gists.ts


示例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
开发者ID:duhongjun,项目名称:blog,代码行数:31,代码来源:about.ts


示例9: createModel

const Repos = createModel({
  state: {
    meta: {
      page: 1,
      perPage: 10,
      total: 0
    },
    repos: []
  },
  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 }
          }
        }
        dispatch.repos.setRepos({ repos, meta: newMeta })
      } catch (err) {
        console.error(err)
      }
    }
  }
})
开发者ID:duhongjun,项目名称:blog,代码行数:49,代码来源:repos.ts


示例10: createModel

const Post = createModel({
  state: {
    post: {},
    comments: []
  },
  reducers: {
    setPost: (state: IPostState, payload: any) => {
      return (state.post = payload)
    },
    setComments: (state: IPostState, payload: any[]) => {
      return (state.comments = payload)
    }
  },
  effects: {
    async getPost(payload: number) {
      let post: ISimpleObj = {}
      try {
        const { data } = await github.get(`/repos/${CONFIG.owner}/${CONFIG.repo}/issues/${payload}`, {
          headers: {
            Accept: 'application/vnd.github.v3.html'
          },
          responseType: 'text'
        })
        post = data
        // post.filter_html = htmlFilter(data.body_html)
        post.filter_html = data.body_html
      } catch (err) {
        console.error(err)
      }
      dispatch.post.setPost(post)
    },
    async getIssuesComments(payload: number) {
      try {
        const { data } = await github.get(`/repos/${CONFIG.owner}/${CONFIG.repo}/issues/${payload}/comments`, {
          headers: {
            Accept: 'application/vnd.github.v3.html'
          },
          responseType: 'text'
        })
        dispatch.post.setComments(data)
      } catch (err) {
        console.error(err)
      }
    }
  }
})
开发者ID:duhongjun,项目名称:blog,代码行数:46,代码来源:post.ts



注:本文中的@rematch/core.createModel函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript grpc-client.Client类代码示例发布时间:2022-05-28
下一篇:
TypeScript testing-utils.cloneableGenerator函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap