npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

troila-mobie-web-utils

v1.0.6

Published

Can only be used internally for the project

Downloads

13

Readme

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