# bara

> Created For Creating - Create any JavaScript application.

Latest version **2.5.0** (published 2019-08-10) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.5.0 |
| Published | 2019-08-10 |
| First published | 2018-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 339.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | nampdn @nampdn |
| Maintainers | nampdn |
| Keywords | bara, reactive programming, trigger, universal, backend, frontend |

## Links

- npm: https://www.npmjs.com/package/bara
- Repository: https://github.com/barajs/bara
- Homepage: https://barajs.dev
- Issues: https://github.com/barajs/bara/issues
- npm.io page: https://npm.io/package/bara

## Dependencies (3)

- [@bara/barn](https://npm.io/package/@bara/barn.md) ^2.5.0
- [@bara/core](https://npm.io/package/@bara/core.md) ^2.5.0
- [@bara/basics](https://npm.io/package/@bara/basics.md) ^2.5.0

## Recent versions

- 2.5.0 (latest) — 2019-08-10
- 2.0.1-alpha.14 (canary) — 2019-04-06
- 2.0.0 (next) — 2019-04-04
- 2.4.0 — 2019-04-24
- 2.3.2 — 2019-04-22
- 2.3.1 — 2019-04-19
- 2.3.0 — 2019-04-19
- 2.2.0 — 2019-04-10
- 2.1.0 — 2019-04-06
- 1.2.0 — 2019-03-05
- 1.1.10 — 2019-03-04
- 1.1.9 — 2019-03-04
- 1.1.8 — 2019-03-04
- 1.1.7 — 2019-03-04
- 1.1.6 — 2019-03-04
- … 7 more at https://npm.io/package/bara/versions

## README

# Bara

Bara is a library created for creating any (front/back/cli) JavaScript application.

## Installation

```
npm install --save bara
```

or

```
yarn add bara
```

## Usage

### Full Application

```javascript
const {
  register,
  useStream,
  useTrigger,
  useEvent,
  useCondition,
  useAction,
  createEventType
} = require('bara')

const ON_TIME_ESLAPSED = createEventType('ON_TIME_ESLAPSED')

const EVERY_X_SECOND = x => second => second % x === 0
const ONLY_EVEN_SECOND = EVERY_X_SECOND(2)

const app = () => {
  // Register source stream factory for Bara application
  useStream(({setName, addEventType, emit}) => {
    setName('dev.barajs.timer')

    let elapsed = 0;
    const timer = setInterval(() => {
        emit(ON_TIME_ESLAPSED, elapsed++);
    }, 1000);

    return () => {
        // Cleanup when zero listener
        clearInterval(timer)
    }
  })

  // Register a trigger that will be triggered every even second
  useTrigger(() => {
    const event = useEvent(ON_TIME_ESLAPSED)
    const condition = useCondition(ONLY_EVEN_SECOND)
    const action = useAction((second) => {
      console.log(`Tik every even seconds: ${second}`)
    })

    return {event, condition, action}
  })

  // Register a trigger that will be triggered every 5 second
  useTrigger(() => {
    const every = 5
    const event = useEvent(ON_TIME_ELAPSED)
    const condition = useCondition(EVERY_X_SECOND(every))
    const action = useAction((second) => {
      console.log(`Tik every `${every}` seconds: ${second}`)
    })

    return {event, condition, action}
  })
}

register(app);
```

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