# jaspp

> Lightweight JavaScript library for building javascript application

Latest version **1.1.0** (published 2020-03-13) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-03-13 |
| First published | 2019-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 30.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Amaury Lavieille |
| Maintainers | alavieille |

## Links

- npm: https://www.npmjs.com/package/jaspp
- Repository: https://github.com/alavieille/jaspp
- Homepage: https://github.com/alavieille/jaspp/blob/master/README.md
- Issues: https://github.com/alavieille/jaspp/issues
- npm.io page: https://npm.io/package/jaspp

## Recent versions

- 1.1.0 (latest) — 2020-03-13
- 1.0.3 — 2020-01-29
- 1.0.2 — 2020-01-29
- 1.0.1 — 2019-11-20
- 1.0.0 — 2019-10-06
- 0.0.10 — 2019-09-30
- 0.0.9 — 2019-09-27
- 0.0.7 — 2019-09-27
- 0.0.6 — 2019-09-27
- 0.0.5 — 2019-09-27
- 0.0.4 — 2019-09-27
- 0.0.3 — 2019-09-27
- 0.0.2 — 2019-09-27
- 0.0.1 — 2019-09-27

## README

# Jaspp

[![Version](https://img.shields.io/npm/v/jaspp.svg?style=flat-square)](https://www.npmjs.com/package/jaspp)
[![License](https://img.shields.io/npm/l/jaspp.svg?style=flat-square)](https://www.npmjs.com/package/jaspp)
[![Downloads](https://img.shields.io/npm/dt/jaspp.svg?style=flat-square)](https://www.npmjs.com/package/jaspp)
![Filesize](https://img.shields.io/bundlephobia/min/jaspp.svg)
![CircleCI](https://img.shields.io/circleci/build/github/alavieille/jaspp/master?style=flat-square)
[![codecov](https://codecov.io/gh/alavieille/jaspp/branch/master/graph/badge.svg)](https://codecov.io/gh/alavieille/jaspp)

Jaspp is Lightweight JavaScript library for handle javascript in a website.

* Tiny < 3kb
* 0 dependencies
* Component oriented
  
### Example

[Todo List](https://alavieille.github.io/jaspp/example/)

### Getting Started


Install Jaspp with npm or yarn: 

```
npm install jaspp
```

Create a component to handle javascript of a DOM Element

```
//components/YourComponent.js

import {AbstractComponent} from 'jaspp'

export default class YourComponent extends AbstractComponent 
{
    render(el) {
        // handle javascript of el element
    }
}

```

Create Application and register your components

```
//index.js
import {Application} from "jasp";
import YourComponent from "components/YourComponent";

const components = {
    'YourComponent' : YourComponent
};

const app = new Application(components);

app.start();

```

If you use webpack, you can use class ComponentsLoader
to load automatically all components inside a folder

```
import {Application, ComponentsLoader} from "../../dist/index.js";

// load all components inside components folder
const components = ComponentsLoader.import(require.context('./components/', true, /\.js$/));
const app = new Application(components);

// ...

```

Activate a component on specific DOM Element
with data attribute *data-view-component* 
and component's name.

```
<div data-view-component="YourComponent">
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  </p>
</section>
```

###### Events

Different events are available in Application: 

* *before:start* is dispatch before render of components
* *after:start* is dispatch after render of components
* *error* is dispatch when there is an error inside a component, it's can be util to log error.


```
//index.js

// ...

const app = new Application(components);

app.start();

app.addEventListener('before:start', (app) => {
  console.log('Application before start event');
});

app.addEventListener('after:start', (app) => {
  console.log('Application after start event');
});

app.addEventListener('error', (exception) => {
  console.log('Application after start event');
});

```

* *dom.update* This event enables components on dynamically added HTML.
```
import {AbstractComponent} from 'jaspp'

class YourComponent extends AbstractComponent 
{
    render(el) {
       const template = `
          <div id="example" data-view-component="OtherComponent"></div>
       `;
       el.insertAdjacentHTML('beforeend', template);
       this.application.dispatch('dom.update', el.querySelector(#example));
    }
}

```

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