fast-on-load
Faster and simplified version of on-load without dom diffing support
Last updated a year ago by bret .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fast-on-load 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.2.0                                ...           latest (a year ago)

5 Versions

  • 1.2.0                                ...           a year ago
  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           2 years ago
Maintainers (2)
Downloads
Today 0
This Week 4
This Month 37
Last Day 2
Last Week 9
Last Month 42
Dependencies (0)
None
Dev Dependencies (6)
Dependents (4)

Copyright 2014 - 2016 © taobao.org |