# bravent

> Functional Event Sourcing

Latest version **0.1.0** (published 2016-09-17) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2016-09-17 |
| First published | 2016-08-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | vvgomes |
| Maintainers | vvgomes |

## Links

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

## Dependencies (3)

- [ramda](https://npm.io/package/ramda.md) ^0.19.1
- [data.maybe](https://npm.io/package/data.maybe.md) 1.2.0
- [data.validation](https://npm.io/package/data.validation.md) ^1.2.0

## Recent versions

- 0.1.0 (latest) — 2016-09-17
- 0.0.9 — 2016-09-17
- 0.0.8 — 2016-09-12
- 0.0.7 — 2016-09-09
- 0.0.6 — 2016-09-09
- 0.0.5 — 2016-09-09
- 0.0.4 — 2016-09-01
- 0.0.3 — 2016-08-30
- 0.0.2 — 2016-08-29
- 0.0.1 — 2016-08-29

## README

# Bravent 🏂

[![build status](https://travis-ci.org/vvgomes/bravent.svg?branch=master)](https://travis-ci.org/vvgomes/bravent)
[![npm version](https://img.shields.io/npm/v/bravent.svg)](https://www.npmjs.com/package/bravent)

Bravent is an [Event Sourcing](http://martinfowler.com/eaaDev/EventSourcing.html) micro framework for Javascript. It is inspired by the [Functional Data](https://vimeo.com/131636650) idea by Greg Young. The goal is to define the abstractions needed for an event sourced application in terms of pure functions and immutable data structures.

## Getting Started

```
$ npm install bravent --save
```

```javascript
import { defineAggregate } from "bravent";

const Counter = defineAggregate({
  initialState: 0,
  eventHandlers: {
    counterIncremented: (state, event) => state + 1,
    counterDecremented: (state, event) => state - 1
  },
  commandHandlers: {
    incrementCounter: (state, command) => [{ type: "counterIncremented" }],
    decrementCounter: (state, command) => [{ type: "counterDecremented" }]
  }
});

// Bravent doesn't impose how you store your events.
let events = [];

// An aggregate instance is a container, like a functor.
const counter = Counter.of(events);
console.log(counter.state()); // => 0

// Dispatching a command returns a new aggregate instance.
// There are no side effects on the original aggregate.
const newCounter =
  counter
    .dispatch({ type: "incrementCounter" })
    .dispatch({ type: "decrementCounter" })
    .dispatch({ type: "incrementCounter" })
    .dispatch({ type: "incrementCounter" });

console.log(newCounter.state()); // => 2

// You can pass callbacks when dispatching commands.
const onSuccess = (newEvents) => console.log("New events:", newEvents);
const onFailure = (errors) => console.log("Errors:", errors);

newCounter.dispatch({ type: "incrementCounter" }, onSuccess, onFailure);
// => New events: [{ type:"counterIncremented" }]

```

For a complete running example, see [bravent-todo](https://github.com/vvgomes/bravent-todo). More documentation coming soon.

## License

Feel free to use this code as you please.

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