0.2.4 • Published 2 years ago

babel-plugin-async-lock v0.2.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

babel plugin for async lock

Prevent unnecessary click callback trigger by fast click. Especcily for async callback, like requesting backend API.

Installation

npm i babel-plugin-async-lock

Usage

// your babel config
module.exports = {
  plugins: [
    'babel-plugin-async-lock',
    {
      exclude: 'node_modules',
      extensions: ['.jsx', '.tsx']
    }
  ]
}

Options

  • exclude
  • extensions

Why

import React from 'react'

function App() {
  const handleClick = async () => {
    const res = await fetch('/api')
  }

  return <button onClick={handleClick}>send request</button>
}

While we fetching api, User can still click the button, and trigger the new fetching, which is unneccessary and mostly unexpected

What the plugin do

it will transform the code, automaticlly add a locker to every async function

Knowing Issue

  • Does't support Class method yet
0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago