# nsignal

> Support for a kind of signal mechanism that specific signal is emitted when an object of mongoose model is created, updated, or deleted.

Latest version **0.0.1** (published 2013-05-28) · MIT license · 0 weekly downloads

## Install

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

## 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.0.1 |
| Published | 2013-05-28 |
| First published | 2013-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Chenxiong Qi |
| Maintainers | tkdchen |
| Keywords | signal, model |

## Links

- npm: https://www.npmjs.com/package/nsignal
- Repository: https://github.com/tkdchen/nsignal
- npm.io page: https://npm.io/package/nsignal

## Dependencies (1)

- [async](https://npm.io/package/async.md) 0.2.x

## Recent versions

- 0.0.1 (latest) — 2013-05-28

## README

# nsignal

nsignal works with Models defined by developers from mongoose' model. nsignal
gives developer the ability to run some functions when related object of Model
has change, like created, updated, or deleted.

# Usage

Define your signal by initialzing an object from Signal class.

    var Signal = require("nsignal");
    var post_save = new Signal({providing_args: ["instance"]});

Register signal receivers in your proper module.

    var SomeModel = require("/path/to/model");

    post_save.connect(SomeModel, function(sender, args, done) {
        console.log("Handle signal here");
        done(null, true);
    });

    // Other receivers
    // ...

``done`` must be called at each exit point within the receiver function.
Function done follows Node callback convention, 

Send signal at some point.

    post_save.send(savedObject, {"instance": savedObject});

where savedObject is the object of SomeModel and just be saved. As an example,
the args passes instance only, which has the same value with the first argument
of method send. Of course, you can pass any arguments through the second
argument, as long as they satisfy the arguments specified while defining
``post_save.``

If you want to handle the result, pass a callback function as the last argument.

    post_save.send(savedObject, {"instance": savedObject}, function(err, results) {
        console.log(">>>", results);
    });

where argument err will be always null, and results is an object of Array
containing each receiver's result and potential error object.

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