# luri-model

> Data binding model.

Latest version **1.0.9** (published 2018-02-26) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install luri-model
pnpm add luri-model
yarn add luri-model
bun add luri-model
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2018-02-26 |
| First published | 2017-09-06 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Manix |
| Maintainers | manix |

## Links

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

## Dependencies (1)

- [luri](https://npm.io/package/luri.md) ^2.4.7

## Recent versions

- 1.0.9 (latest) — 2018-02-26
- 1.0.8 — 2018-02-25
- 1.0.7 — 2018-02-25
- 1.0.6 — 2018-02-24
- 1.0.5 — 2018-02-23
- 1.0.4 — 2017-10-18
- 1.0.3 — 2017-09-10
- 1.0.2 — 2017-09-09
- 1.0.1 — 2017-09-08
- 1.0.0 — 2017-09-06

## README

# luri-model

### What is this
This is an extension for luri which allows binding between javascript objects and DOM elements.

### How to use
The binding is realized explicitly by utilizing luri's event system. The model class acts like a factory 
and produces luri components which listen for changes on the model's properties and get updated accordingly.

    const Model = require("luri-model");

    class User extends Model {

      // Whatever methods there may be

    }

    let Auth = new User({
      id: 1,
      name: "Manix",
      age: 24
    });

    document.body.appendChild(luri.construct([
      luri.H1("Authenticated user info"),
      ["Name: ", Auth.prop("name")],
      ["Age: ", Auth.prop("age")]
    ]));

Then

    Auth.set("age", 25);
    
 As explained above, the `prop` method returns a luri component, the function definition is as follows
 
    prop(prop, def = {}, renderer = null)
    
 * `prop` is the name of the property the component will listen for.
 * `def` is the definition the component will render, see [concepts](https://github.com/luri/lib#concepts) for more info.
 * `renderer` is a function that gets called whenever a change occurs and is responsible for modifying the DOM. It is passed 
 the model as the first argument and the property that changed or undefined as the second one. Typically you want to avoid passing this parameter, however it's available for the rare cases 
 when it's needed.

## Utility

#### Magic properties

You can define "magic" properties in the model class which will allow you to easily get or set values from its instances.

If we continue the example above, we can add magic methods to the user class by executing

    User.magic(["name", "age"]);
    
And then we are able to call the respective methods on its instances

    Auth.name(); // returns "Manix"
    Auth.age(25); // sets the age to 25
    Auth.age(); // returns 25

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