# reactive-plugin-system

> Plugin / addon / extension system using ES Observables

Latest version **0.0.1** (published 2018-09-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install reactive-plugin-system
pnpm add reactive-plugin-system
yarn add reactive-plugin-system
bun add reactive-plugin-system
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2018-09-02 |
| First published | 2018-09-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | AndSelm |
| Maintainers | andselm |
| Keywords | reactive, frp, Rx, RxJS, bacon, bacon.js, Observable, kefir, kefir.js, stream, streams, addon, extension, plugin |

## Links

- npm: https://www.npmjs.com/package/reactive-plugin-system
- Repository: https://github.com/FunkMonkey/reactive-plugin-system
- Issues: https://github.com/FunkMonkey/reactive-plugin-system/issues
- npm.io page: https://npm.io/package/reactive-plugin-system

## Dependencies (1)

- [rxjs](https://npm.io/package/rxjs.md) 5.4.2

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2018-09-02

## README

# reactive-plugin-system

`reactive-plugin-system` is an addon / extension / plugin system for JavaScript.
It uses [RxJS5](https://github.com/ReactiveX/rxjs) to handle asynchronous loading
and unloading of plugins. Plugins can depend on each other.

## Example

A simple plugin system that uses `require` to load plugins.

### some-app.js

```js
import { PluginSystem, factoryLoaders } from 'reactive-plugin-system';

const plugins = new PluginSystem( {
  data: 'shared',
  getFactory: factoryLoaders.require
} );

plugins.loadAndWaitForAll( 'plugin-a', `plugin-b`, `plugin-c` );
  .subscribe( ( [pluginA, pluginB, pluginC] ) => {
    pluginB.doSomething();
    plugins.unload( 'pluginC' ); // unloading and cleaning up
  } );
```

### plugin-a/index.js

`PluginA` loads asynchronously and uses shared data.

```js
class PluginA {
  constructor( data ) {
    this.data = data;
  }

  printData() {
    console.log( this.data );
  }
}

export default function pluginAFactory( data ) {
  return Rx.Observable.timer( 1000 ) // wait a second
    .map( () => new PluginA( data ) );
}
```

### plugin-b/index.js

`PluginB` depends on `PluginA`.

```js
class PluginB {
  constructor( pluginA ) {
    this.pluginA = pluginA;
  }

  doSomething() {
    this.pluginA.printData();
  }
}

export default function pluginBFactory( data, pluginSystem ) {
  return pluginSystem.waitFor( 'plugin-a' )
    .map( pluginA => new PluginB( pluginA ) );
}
```

### plugin-c/index.js

`PluginC` needs to clean up in the end.

```js
import { Observable } from 'rxjs';

class PluginC {
  cleanup() {
    // do cleanup
  }
}

export default function pluginCFactory() {
  return new Observable( observer => {
    const pluginC = new PluginC();

    observer.next( pluginC );
    observer.complete();

    return () => pluginC.cleanup();
  } );
}
```

## API

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