1.0.6 • Published 5 years ago

@shockw4ver/class v1.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Shockw4ver/class

There are something make you happy...😎

autobind-lite

A tiny autobind decorator, mainly be useful with function declaration in ReactJS class components.

  • Usage

    import React from 'react'
    import { autobind } from '@shockw4ver/class'
    
    export default class extends React.Component {
      state = {
        msg: 'Hellow world!'
      }
    
      @autobind
      handleClick () {
        // 👇 Got TypeError if you didn't use `autobind` or other ways to bind `handleClick` on your class.
        const { msg } = this.state
        alert(msg)
      }
    
      render () {
        return <button onClick={this.handleClick}></button>
      }
    }

only

To limit times could a delay function be called at same time.

  • Usage

    Pretend to has a case with when method in mobx.

    import { observable, when } from 'mobx'
    
    class UserStore {
      @observable isLogin = false
      @observable data = {}
    
      @only(1)
      async fetchData () {
        when(() => isLogin === true)
    
        const res = await fetch('some_url')
    
        this.data = res.json()
      }
    }

    If there're two components without any relationshiop but call the fetchData at the same time, with only(1), there will just one fetchData works, and all of them will react to the store.

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago