Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nanocomponent

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nanocomponent

Create performant HTML elements

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
449
decreased by-17.01%
Maintainers
1
Weekly downloads
 
Created
Source

nanocomponent stability

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

Create performant HTML elements.

Features

  • works with every framework
  • significantly speeds up perceived performance
  • improves rendering performance
  • graciously falls back if APIs are not available
  • weighs ~2kb

Usage

Cache a static HTML element

var component = require('nanocomponent')
var html = require('bel')

var staticElement = component(html`
  <div>heya</div>
`)
console.log(staticElement())

Cache a dynamic HTML element

var cachedElement = component(function (foo) {
  return html`
    <div>${foo}</div>
  `
})
console.log(cachedElement())

Defer rendering until the browser has spare time available

var politeElement = component({
  placeholder: function () {
    return html`
      <p>lol not loaded yet</p>
    `
  },
  render: function () {
    return html`
      <p>HOW'S IT GOING CHAP</p>
    `
  }
})
console.log(politeElement())

Trigger lifecycle events when loading and unloading elements to the DOM

var widgetElement = component({
  onload: function () {
  },
  onunload: function (el) {
  },
  onupdate: function (foo, bar) {
    // do stuff with new arguments
  },
  render: function (foo, bar) {
    return html`
      <p>lol not loaded yet</p>
    `
  }
})
console.log(widgetElement())

API

render = nanocomponent(HtmlOrFunctionOrObject)

Create a render function for a component based depending on the arguments that are passed in:

  • HTMLElement: when a valid HTML node is passed
  • function: cache the result of the function until new arguments are passed
  • object: create an object with different methods attached

el = render(...args)

Installation

$ npm install nanocomponent

License

MIT

Keywords

FAQs

Package last updated on 04 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc