nanomorph-guard
Guard element against being touched by nanomorph
Last updated 2 years ago by emilbayes .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install nanomorph-guard 
SYNC missed versions from official npm registry.

nanomorph-guard

Build Status

Guard element against being touched by nanomorph

Requires nanomorph@5.4.0 or up.

Usage

Useful with components that expect to keep a reference to their parent element, but that you still would like to use in combination with nanomorph

Below is an example that manually updates a text node every second, while only morphing the DOM every five seconds. The reference to manualElm is not lost.

var guard = require('nanomorph-guard')
var morph = require('nanomorph')
var html = require('nanohtml')

var manualElm = document.createElement('p')
var text = document.createTextNode()
manualElm.appendChild(text)

function updateMorph () {
  morph(document.body, html`<body>
    <p>Updated by nanomorph on ${Date.now()}</p>
    ${guard(manualElm)}
  </body>`)
}

function updateManual () {
  text.textContent = `Updated by manually on ${Date.now()}`
}

setInterval(updateManual, 1000)
setInterval(updateMorph, 5000)

API

var el = guard(element)

Protect element from being morphed by nanomorph. Will return element itself if not a Node, eg. string, DocumentFragment, array or other types that you may sometimes pass to nanohtml/nanomorph

Install

npm install nanomorph-guard

License

ISC

Current Tags

  • 2.1.0                                ...           latest (2 years ago)

4 Versions

  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 1
This Week 11
This Month 11
Last Day 10
Last Week 8
Last Month 43
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |