Socket
Book a DemoInstallSign in
Socket

fast-on-load

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-on-load

Faster and simplified version of on-load without dom diffing support

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
2
Created
Source

fast-on-load

Build Status

Faster and simplified version of on-load without dom diffing support.

Usage

const onload = require('fast-on-load')

onload(domElement, function () {
  console.log('element was mounted')
}, function () {
  console.log('element was unmounted')
})

Uses a MutationObserver and a generated class together with getElementsByClassName() to find DOM nodes that on-load is tracking, which performs much faster (around 1000x in our machines) on bigger DOM trees that the tree traversal algo on-load uses.

API

const node = onload(node, [onload], [onunload])

Watch node, optionally passing onload and onunload handler. Returns the node itself.

onload.delete(node, [onload], [onunload])

Pass in references to the onload and onunload functions and the node they are attached to to remove them from the function set that get run on load and unload. Pass undefined for onload if you only attached and onunload function.

onload = onload.bind(dom.window)

To run in non-dom context, such as jsdom, call onload with desired window context.

Install

npm install fast-on-load

License

MIT

FAQs

Package last updated on 30 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts