# nanomorph-guard

> Guard element against being touched by nanomorph

Latest version **2.1.0** (published 2019-03-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install nanomorph-guard
pnpm add nanomorph-guard
yarn add nanomorph-guard
bun add nanomorph-guard
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2019-03-13 |
| First published | 2019-01-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Hyperdivision |
| Maintainers | emilbayes |

## Links

- npm: https://www.npmjs.com/package/nanomorph-guard
- Repository: https://github.com/hyperdivision/nanomorph-guard
- Homepage: https://github.com/hyperdivision/nanomorph-guard#readme
- Issues: https://github.com/hyperdivision/nanomorph-guard/issues
- npm.io page: https://npm.io/package/nanomorph-guard

## Recent versions

- 2.1.0 (latest) — 2019-03-13
- 2.0.0 — 2019-03-13
- 1.0.1 — 2019-03-13
- 1.0.0 — 2019-01-24

## README

# `nanomorph-guard`

[![Build Status](https://travis-ci.com/hyperdivision/nanomorph-guard.svg?branch=master)](https://travis-ci.com/hyperdivision/nanomorph-guard)

> Guard element against being touched by nanomorph

<small>Requires nanomorph@5.4.0 or up.</small>

## 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.

```js
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

```sh
npm install nanomorph-guard
```

## License

[ISC](LICENSE)

---
_Source: https://npm.io/package/nanomorph-guard · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
