# dover

> Immutable state objects with event channels

Latest version **1.2.0** (published 2016-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install dover
pnpm add dover
yarn add dover
bun add dover
```

## 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 | 1.2.0 |
| Published | 2016-02-28 |
| First published | 2015-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Ben Drucker |
| Maintainers | bendrucker |
| Keywords | channels, event, immutable, mercury |

## Links

- npm: https://www.npmjs.com/package/dover
- Repository: https://github.com/bendrucker/dover
- Homepage: https://github.com/bendrucker/dover#readme
- Issues: https://github.com/bendrucker/dover/issues
- npm.io page: https://npm.io/package/dover

## Dependencies (6)

- [xtend](https://npm.io/package/xtend.md) ~4.0.0
- [is-obj](https://npm.io/package/is-obj.md) ~1.0.0
- [observ](https://npm.io/package/observ.md) ~0.2.0
- [map-values](https://npm.io/package/map-values.md) ~1.0.1
- [dom-delegator](https://npm.io/package/dom-delegator.md) ~13.1.0
- [observ-struct](https://npm.io/package/observ-struct.md) ~6.0.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.2.0 (latest) — 2016-02-28
- 1.1.0 — 2015-08-03
- 1.0.0 — 2015-07-28

## README

# dover [![Build Status](https://travis-ci.org/bendrucker/dover.svg?branch=master)](https://travis-ci.org/bendrucker/dover)

> Immutable state objects with event channels, inspired by [Mercury](https://github.com/raynos/mercury)

## Install

```
$ npm install --save dover
```

## Usage

Dover uses [observ-struct](https://github.com/raynos/observ-struct) to manage data, adding a special case for `channels`. Channels are event-handling functions that are bound to the immutable created by observ-struct. All state mutations that flow from UI events can *only* flow through channels.

```js
var State = require('dover')
var Observ = require('observ')
var h = require('virtual-dom/h')

function Component (data) {
  data = data || {}
  return State({
    title: Observ(data.title || 'My Great Post'),
    selected: Observ(data.selected || false),
    channels: {
      toggle: toggle
    }  
  })
}

function toggle (state) {
  state.selected.set(!state.selected())
}

Component.render = function (state) {
  var text = state.title
  if (state.selected) text += ' (Selected)'
  return h('h1', {onclick: state.channels.toggle}, text)
}

var component = Component()
// re-render any time data changes
component(Component.render)
// perform our initial render
Component.render(component())
```

In the above example, we bind the click event to `toggle`, but can never directly call it from `Component.render`. Dover binds `toggle` to the immutable state internally and ensures that `state.channels.toggle` is no longer a function, but a reference to the internal function inside the [DOM event delegation system](https://github.com/raynos/dom-delegator).

If we try to call `toggle` directly from within `Component.render`, we'll see an error because `state.selected` is a plain value, not an observable with a `set` method as it is inside our `Component` constructor.

## API

#### `State(state)` -> `function`

##### state

*Required*  
Type: `object`

The state object to be converted into an observable struct. This state object is identical to the one provided to [observ-struct](https://github.com/raynos/observ-struct), but performs delegation/state binding as described in **Usage** on the optional `channels` property.

## License

MIT © [Ben Drucker](http://bendrucker.me)

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