Giter Club home page Giter Club logo

lazy-js-utils's Introduction

lazy-js-utils

NPM version NPM version NPM version

🖥 文档

English | 简体中文

目前整理了200 左右的常用函数,还在持续更新中...,你的认可是对我最大的鼓励 ♥️

💯 亮点

  • 纯 js 的工具函数,可使用在任何可执行 js 的环境
  • 大量减少ref<HTMLElment>onMounted的使用,可以 script 标签直接调用
  • 所有的副作用函数都能返回一个 stop 函数,可以在任意地方停止事件的执行,并且在页面销毁时自动销毁事件
  • api 设计简单、实用、类型友好

✋ 例子

import {
  insertElement,
  useEventListener,
  useMutationObserver,
  useRaf,
} from 'lazy-js-utils'

// 监听container的变化, 你不在需要const container = ref<HTMLElement>
useMutationObserver('#container', (mutationsList, observer) => {
  console.log(mutationsList)
})
// requestAnimationFrame
useRaf(
  (timestamp) => {
    // 每针相隔1s执行
    console.log('animationFrame', timestamp)
  },
  1000,
  true /* 只执行一次后被销毁 */,
)
// 注册事件
useEventListener('#container', 'click', () => {
  console.log('click')
})
// 插入元素
insertElement('#container', '.content')
// 删除元素
removeElement('.content')
<div id="container"></div>
<div class="content">hello world</div>

📖 使用说明

npm i lazy-js-utils // 安装

import {
  deepCompare
 } from 'lazy-js-utils' // 按需引入

👉 文档

请我喝一杯咖啡

License

MIT

GitHub 地址

欢迎 PR

lazy-js-utils's People

Contributors

simon-he95 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.