|
10 | 10 |
|
11 | 11 | At present, I have sorted out <strong>100+</strong> commonly used functions, and I am still updating..., and your recognition is the biggest encouragement to me :hearts: |
12 | 12 |
|
13 | | -## 🔥 Highlights |
14 | | -- Pure js tool functions, not dependent on vue, react, angular |
15 | | -- API encapsulation for dom operations, such as those used in vue, does not require onMounted to obtain dom nodes, and can be passed in directly using class or id |
16 | | -- Side effect functions, which can be destop as a result of function execution, are also automatically stopped when the page is destroyed |
17 | | -- Api design is simple and practical |
| 13 | +## :100: Highlights |
| 14 | +- Pure JS utility functions, Can be used in any environment where JS can be executed |
| 15 | +- Greatly reduced the use of `ref<HTMLElment>` and `onMounted`, which can be called directly from the script tag |
| 16 | +- 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 |
| 17 | +- API design is simple, practical and type-friendly |
| 18 | + |
| 19 | +## ✋ Example |
| 20 | +```js |
| 21 | +import { addEventListener, animationFrameWrapper, insertElement, useMutationObserver } from 'simon-js-tool' |
| 22 | +// To listen for container changes, you don't need const container <HTMLElement>= ref |
| 23 | +useMutationObserver('#container', (mutationsList, observer) => { |
| 24 | + console.log(mutationsList) |
| 25 | +}) |
| 26 | +// requestAnimationFrame |
| 27 | +animationFrameWrapper((timestamp) => { |
| 28 | + // Each needle is executed 1s apart |
| 29 | + console.log('animationFrame', timestamp) |
| 30 | +}, 1000, true /* It is destroyed after only one execution */) |
| 31 | +// Register for events |
| 32 | +addEventListener('#container', 'click', () => { |
| 33 | + console.log('click') |
| 34 | +}) |
| 35 | +// Insert an element |
| 36 | +insertElement('#container', '.content') |
| 37 | +// Delete an element |
| 38 | +removeElement('.content') |
| 39 | +``` |
| 40 | +```html |
| 41 | +<div id="container"></div> |
| 42 | +<div class="content">hello world</div> |
| 43 | +``` |
18 | 44 |
|
19 | 45 | ## :balloon: More |
20 | 46 | - Export function [exports-function](https://github.com/SimonHe1995/exportsFunction) |
|
0 commit comments