# modl-js

> A mutation base model management library, inspired by the Flux pattern

Latest version **0.4.0** (published 2017-10-24) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install modl-js
pnpm add modl-js
yarn add modl-js
bun add modl-js
```

## 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.4.0 |
| Published | 2017-10-24 |
| First published | 2017-10-16 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | David Balan |
| Maintainers | neopixl |
| Keywords | models, modl, flux, data |

## Links

- npm: https://www.npmjs.com/package/modl-js
- npm.io page: https://npm.io/package/modl-js

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2017-10-24
- 0.3.0 — 2017-10-23
- 0.2.0 — 2017-10-17
- 0.1.4 — 2017-10-16
- 0.1.3 — 2017-10-16
- 0.1.2 — 2017-10-16
- 0.1.1 — 2017-10-16
- 0.1.0 — 2017-10-16

## README

# Modl

A mutation base model management library, inspired by the Flux pattern.

## Install

```
# yarn
yarn add modl-js
# npm
npm install modl-js
```

## Usage

```js
import Modl from 'modl-js';

Modl.use(Modl.middlewares.type)
    .use(Modl.middlewares.default);

const Person = Modl({
  fields: {
    fisrtName: {
      type: String
    },
    lastName: {
      type: String
    },
    birthDate: {
      type: Date,
      default() { 
        return new Date(); 
      }
    }
  },
  computed: {
    age(store) {
      const ageDif = new Date(Date.now() - store.birthDate.getTime());
      return Math.abs(ageDate.getUTCFullYear() - 1970);
    }
  }
});

const me = new Person({ 
  firstName: 'mod', 
  lastName: 'elo', 
  birthDate: new Date('2017-10-15T15:45:48Z') 
});
```

## Mutating

```js
import Modl from 'modl-js';

const Person = Modl({
  fields: {
    fisrtName: {
      type: String
    }
  },
  mutations: {
    CHANGE_NAME(store, name) {
      store.name = name;
    }
  }
});

const me = new Person({ 
  firstName: 'modl'
});
me.mutated(() => { console.info('changed'); });
me.commit('CHANGE_NAME', 'bob');
```

## Actions

```js
import Modl from 'modl-js';

const Person = Modl({
  fields: {
    fisrtName: {
      type: String
    }
  },
  mutations: {
    CHANGE_NAME(store, name) {
      store.name = name;
    }
  },
  actions: {
    setName(store, name) {
      return new Promise((resolve) => {
        setTimeout(() => {
          store.commit('CHANGE_NAME', name);
          resolve();
        }, 3000);
      });
    }
  }
});

const me = new Person({ 
  firstName: 'modl'
});
me.mutated(() => { console.info('changed'); });
me.setName('bob').then(() => {
  console.info('done');
});
```

## Run tests

```
npm run test
```

## Build

```
npm run build
```

## Requirement

 - `Object.assign`
 - `Array.concat`
 - `WeakMap`
 - `Set`


## Road map

 - [x] Properties management
 - [x] Actions and mutations management
 - [x] Properties extansibility
 - [x] Inheritance
 - [x] Flat inheritance
 - [] Behavior management
 - [] Documentation

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