Socket
Book a DemoInstallSign in
Socket

macrocomponent

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

macrocomponent

Convenience wrapper around nanocomponent, for the most common case

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

macrocomponent

Convenience wrapper around the nanocomponent DOM component library, for the most common case.

Example

Instead of this boilerplate-y thing:

const Component = require('nanocomponent')
const html = require('bel')
const morph = require('nanomorph')
const inherits = require('util').inherits

function View () {
  Component.call(this)
  this.foo = null
  this.bar = null
}

inherits(View, Component)

View.prototype._update = function (state) {
  return state.foo !== this.foo
    || state.bar !== this.bar  
}

View.prototype._render = function (state) {
  this.foo = state.foo
  this.bar = state.bar
  const el = html`
    <p>
      Hey ${state.foo}, how are you ${state.bar}ing?
    </p>
  `
  if (this._element) morph(this._element, el)
  else this._element = el
  return this._element
}

You can now do this:

const component = require('macrocomponent')

const view = component(() => `
  <p>
    Hey ${this.props.foo}, how are you ${this.props.bar}ing?
  </p>
`)

..and it implements the same logic!

Installation

$ npm install macrocomponent

API

component(render)

License

MIT

FAQs

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