Git Product home page Git Product logo

troila-mobie-web-utils's Introduction

ws-web-utils

Can only be used internally for the project

Install

$ npm install --save ws-web-utils

API

stateHoc([options])(Component)

stateHoc是一个高阶组件,用于处理业务组件的等待、请求、异常处理显示等...

[options] (Object)

  • Loading (Class/Func): loading状态下的显示组件

  • Failure (Class/Func): failure状态下的显示组件

  • Error (Class/Func): error状态下的显示组件

  • NullData (Class/Func): nullData状态下的显示组件

  • detail (Boolean): 如果 true ,则会通过 hocDetailKey 来获得key值用来处理渲染判断

  • hocDetailKey (Function): 要求返回一个string类型的值,这个值是props.fetchStatus的渲染键名

  • fetchStatus (String or Object):

    default模式下要求是string类型,遵循fetchStatus渲染规则(如下)。
    detail模式下要求是object类型,取object[key]来用于判断渲染,遵循fetchStatus渲染规则(如下)

  • hocNullDataFunc (Function): 默认null,如果设置,则需要返回一个boolean值,用于判断是否显示NullData组件

Component

子组件下的成员方法

  • hocComponentDidMount (Function): 如果存在,会在高级组件的render后像componentDidMount一样的生命周期执行,常用语fetch请求等

Examples
import {stateHoc,fetchStatus} from 'ws-web-utils'
import { connect } from "react-redux";

//默认模式
@connect(()=>({
    fetchStatus: fetchStatus.s
}))
@stateHoc()
class HourseDetail extends Component{
    hocComponentDidMount() {
        //todo more
    }
    render(){
        return <div>success</div>
    }
}

//detail模式
@connect(()=>({
    fetchStatus: {
        '1': fetchStatus.s
    }
}))
@stateHoc({
    detail: true
})
class HourseDetail extends Component{
    hocDetailKey(){
        return '1'
    }
    hocComponentDidMount() {
        //todo fetch
    }
    render(){
        return <div>success</div>
    }
}

fetchStatus (Object)

  • l loading
  • f failure
  • e error
  • s success

Examples
import {fetchStatus} from 'ws-web-utils'
console.log(fetchStatus)
/*
    {
        l: 'loading',
        f: 'failuer',
        e: 'error',
        s: 'success',
    }
*/

fetchStatus渲染规则

  • fetchStatus.l render Loading
  • fetchStatus.f render Failure
  • fetchStatus.e render Error
  • fetchStatus.s render 包裹的组件

废旧文档 (忽略以下)


stateHoc API (props , params)

options Config

Param Default Type Description
Loading Loading Class/Func 等待状态
Failure Failure Class/Func 失败状态
Error Error Class/Func 错误状态
detail false Boolean 使用场景是多个state
keyFunc undefined Func detail==true时有效,捆绑key生效
key undefined String detail==true时有效,取值唯一标识
height undefined Number LoadingView的height props

Props Config

Prop Default Type Description
fetchStatus undefined String 详见内部FetchStatus
orther props ...this.props Object ...

troila-mobie-web-utils's People

Contributors

xuanhescript avatar

Watchers

 avatar  avatar  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.