@shockw4ver/class
v1.0.6
Published
Some useful class tools, maybe.
Downloads
2
Readme
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, withonly(1)
, there will just onefetchData
works, and all of them will react to the store.