# de

> Simple asynchronous promise-based controller

Latest version **4.0.0** (published 2013-12-25) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2013-12-25 |
| First published | 2013-09-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Golyshev Dmitrii |
| Maintainers | golyshevd |

## Links

- npm: https://www.npmjs.com/package/de
- Repository: https://github.com/golyshevd/Model
- Issues: https://github.com/golyshevd/Model/issues
- npm.io page: https://npm.io/package/de

## Dependencies (2)

- [node-ns](https://npm.io/package/node-ns.md) git://github.com/golyshevd/Namespace.git#v1.0.x
- [jspromise](https://npm.io/package/jspromise.md) git://github.com/golyshevd/JSPromise.git#v1.0.x

## Recent versions

- 4.0.0 (latest) — 2013-12-25
- 3.0.0 — 2013-12-16
- 1.1.0 — 2013-10-17
- 1.0.0 — 2013-10-17
- 0.1.5 — 2013-10-14
- 0.1.4 — 2013-10-12
- 0.1.3 — 2013-10-11
- 0.1.2 — 2013-10-08
- 0.1.1 — 2013-10-07
- 0.1.0 — 2013-09-30
- 0.0.1 — 2013-09-29

## README

de [![Build Status](https://travis-ci.org/golyshevd/Model.png?branch=v4.0.x)](https://travis-ci.org/golyshevd/Model)
==========

Simple asynchronous promise based data agent

Lazy example
---------
```js

var Exception;
var Promise;
var StdProvider;
var StdRuntime;

var agent;

Exception = require('de/util/Exception');
Promise = require('jspromise');
StdProvider = require('de/Provider');
StdRuntime = require('de/util/Runtime');

function Runtime () {
  StdRuntime.apply(this, arguments);
}

Runtime.prototype = Object.create(StdRuntime.prototype);

//  my Runtime turbo extension
Runtime.prototype.getRequest = function () {
  return this.params.request;
};

function Provider () {
  StdProvider.apply(this, arguments);
}

Provider.prototype = Object.create(StdProvider.prototype);

//  @overrides default method
Provider.prototype._createRuntime = function (params) {
  
  return new Runtime(this, params);
};

agent = new Provider();

//  data declaration (polymorphic)
agent.decl('my-data-3', {
  deps: ['my-data-1', 'my-async-data', 'url', 'some-bad'],
  data: function (result, errors) {
    
    console.log(errors['some-bad']); // 9000
    
    return result['my-data-1'] + result.myAsyncData + url.query.some;
  },
  alias: 'myData3'
});

agent.decl('my-data-1', 42);

agent.decl('my-async-data', {
  alias: 'myAsyncData',
  deps: 'url',
  data: function (result, errors) {
  
  //  the only way to return data asynchronously (U can use ANY compilant promises/A+ implementation)
    var promise;
    
    promise = new JSPromise();
    
    setTimeout(function () {
      promise.fulfill(result.url.query.data));
    }, 5000);
    
    return promise;
  }
});

agent.decl('url', function () {
  
  var req;
  
  req = this.getRequest();
  
  console.log(this instanceof Runtime); //  true
  
  return Url.parse(req.url, true);
});

agent.decl('some-bad', function () {
  throw 9000;
});

//  data providing
agent.provide({request: {
  url: '/a/b/c/?data=5&some=6'
} }, ['my-data-3']).then(function (data) {
  
  console.log(data.result.myData3); // 5 + 6 + 42
});

```

To reject provide() promise u can throw an ```{de/util/Exception}``` instance inside data function.
data can be any value or promise object, not only function

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