English | 简体中文
At present, I have sorted out about 200 commonly used functions, and I am still updating..., and your recognition is the biggest encouragement to me
- Pure JS utility functions, Can be used in any environment where JS can be executed
- Greatly reduced the use of
ref<HTMLElment>
andonMounted
, which can be called directly from the script tag - All side effect functions can return a stop function, which can stop the execution of the event anywhere, and automatically destroy the event when the page is destroyed
- API design is simple, practical and type-friendly
import {
animationFrameWrapper,
insertElement,
useEventListener,
useMutationObserver,
} from 'lazy-js-utils'
// To listen for container changes, you don't need const container <HTMLElement>= ref
useMutationObserver('#container', (mutationsList, observer) => {
console.log(mutationsList)
})
// requestAnimationFrame
animationFrameWrapper(
(timestamp) => {
// Each needle is executed 1s apart
console.log('animationFrame', timestamp)
},
1000,
true /* It is destroyed after only one execution */,
)
// Register for events
useEventListener('#container', 'click', () => {
console.log('click')
})
// Insert an element
insertElement('#container', '.content')
// Delete an element
removeElement('.content')
<div id="container"></div>
<div class="content">hello world</div>
npm i lazy-js-utils // Installation
import {
deepCompare
} from 'lazy-js-utils' // Ingestion on demand