Giter Club home page Giter Club logo

soda-taro-base's Introduction

Mobile App By Taro

used:Taro、redux、redux-saga、sass、Typescript (nodejs v10.15.1、@tarojs/cli v2.0.7)

TaroCli 全局安装 (必须)

# 使用 npm 安装 CLI
$ npm install -g @tarojs/[email protected]

# OR 使用 yarn 安装 CLI
$ yarn global add @tarojs/[email protected]

# OR 安装了 cnpm,使用 cnpm 安装 CLI
$ cnpm install -g @tarojs/[email protected]

安装

$ npm install / yarn install

启动

$ npm run dev:h5 / yarn dev:h5

# Mac
$ ./run.sh dev:h5

新增路由

# 务必安装全局工具 soda-bo-cli
$ sbc new PageName   # 支持多级目录 例如: sbc new User/Update

编译

$ npm run build:** / yarn build:**

关于数据流

创建reducer 和 action(插件会遍历src/pages下的所有redux.ts文件):

// src/pages/Index/redux.ts

export const list = buildRedux('IndexBanner')({
  url: api.login,  // * (payload, {getState}) => '/url'
  method: 'get',
})
export const detail = buildRedux('BannerDetail')({
  url: api.login,  // * (payload, {getState}) => '/url'
  method: 'get',
})

以上会创建:

state action
state.Index.list Action.IndexBanner.start()/Action.IndexBanner.start()...
state.Index.detail Action.BannerDetail.start()/Action.BannerDetail.start()...

state.Index.liststate.Index.detail 中的 Index 为 文件夹名称 pages/Index/redux.ts 中的Index(多级目录 /pages/User/Login => UserLogin``)。buildRedux 中的第一个参数则是 Action的名称。

Actionimport { Action } from 'store/helper' 提供

你依然可以通过connect方法来连接调用 => @connect(state => {...}, dispatch => {...})

state关联数据:

'store/helper' 提供了 inject 方法(此方法只能关联整个模块到组件,且不能自定义名称, 只是提供了自能提示):

import { inject } from 'store/helper'

@inject('Index')
class Home extends Taro.PureComponent {
  componentDidMount() {
    this.props.Index // {list: {...}, detail: {...}}
  }
}

inject 参数为字符串 或者 数组

state结构图为:

soda-taro-base's People

Contributors

jiangwanwei avatar

Watchers

 avatar Joyer.Z avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.