# signals-slots

> SignalJS is an implementation of signals/slots system in JavaScript.

Latest version **0.1.3** (published 2016-06-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install signals-slots
pnpm add signals-slots
yarn add signals-slots
bun add signals-slots
```

## 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.1.3 |
| Published | 2016-06-01 |
| First published | 2016-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Ye Liu |
| Maintainers | jaux |
| Keywords | signal, signals-slots, event |

## Links

- npm: https://www.npmjs.com/package/signals-slots
- Repository: https://github.com/jaux/signal.js
- Homepage: https://github.com/jaux/signal.js#readme
- Issues: https://github.com/jaux/signal.js/issues
- npm.io page: https://npm.io/package/signals-slots

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.1.3 (latest) — 2016-06-01

## README

# Signals/Slots in JavaScript

SignalJS is a minimalist implementation of [signals/slots system][1] in JavaScript.

[1]: http://en.wikipedia.org/wiki/Signals_and_slots "Wikipedia Entry"

## How to Use

Say I have an app called *MyApp*, it has two objects `MyApp.X` and `MyApp.Y`.
Now, `MyApp.Y` wants to be notified if there are some events happened on
`MyApp.X`. To accomplish this task, I just need the following few steps:

1. Clone this repo and add `signal.js` to my HTML

    ```html
    <script src="path/to/signal.js"></script>
    ```

2. Create a signal and attach it to `MyApp` namespace, so it can be accessed by
   both `MyApp.X` and `MyApp.Y`

    ```javascript
    MyApp.dummySignal = Signal.create('dummySignal');
    ```

3. Connect `MyApp.Y` to the just created signal

    ```javascript
    MyApp.Y.signalHandler = function(sender, data) {
        console.log('Received a dummySignal from sender with data');
    };

    MyApp.dummySignal.connect(MyApp.Y.signalHandler, MyApp.Y);
    ```

4. Let `MyApp.X` send the signal when some event is happened

    ```javascript
    MyApp.X.http.get('/data').
        success(function(response) {
            /*
             * Got new data, send signal to notify whomever is connected. In
             * this example, `MyApp.Y.signalHandler` will be called.
             */
            MyApp.dummySignal.emit(MyApp.X, response);
        });
    ```

5. That's it!

[Live DEMO](http://plnkr.co/edit/pGs57j?p=preview)

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