New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

polite-element

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polite-element

Wait to render until a the browser has less load

1.0.0
Version published
Maintainers
1
Created

polite-element stability

npm version build status test coverage downloads js-standard-style

Politely waits to render an element until the browser has time to spare using window.requestIdleCallback(). Useful to create incrementally loading applications that don't block user interaction.

Usage

var polite = require('polite-element')
var html = require('bel')

var el = html`
  <main>
    ${polite(basicRender, renderFancy)}
  </main>
`
document.body.appendChild(el)

function renderBasic () {
  return html`
    <img alt="ms. floof" />
  `
}

function renderFancy () {
  return html`
    <img src="https://cool-cat.pix/meow" alt="ms. floof" />
  `
}

API

el = politeElement(renderBasic, renderFancy)

Create an initial element on load using renderBasic. Once the browser is less busy it will call the renderFancy function to load a more complex element. Always calls renderBasic when run in Node.

Installation

$ npm install polite-element

See Also

License

MIT

FAQs

Package last updated on 03 Jan 2017

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