# overmind-plugin

> A plugin system for overmind

Latest version **1.0.5** (published 2018-10-08) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install overmind-plugin
pnpm add overmind-plugin
yarn add overmind-plugin
bun add overmind-plugin
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2018-10-08 |
| First published | 2018-10-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 18.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Etienne Dldc |
| Maintainers | etienne-dldc |

## Links

- npm: https://www.npmjs.com/package/overmind-plugin
- Repository: https://github.com/etienne-dldc/overmind-plugin
- Homepage: https://github.com/etienne-dldc/overmind-plugin#readme
- Issues: https://github.com/etienne-dldc/overmind-plugin/issues
- npm.io page: https://npm.io/package/overmind-plugin

## Dependencies (1)

- [is-plain-object](https://npm.io/package/is-plain-object.md) ^2.0.4

## Recent versions

- 1.0.5 (latest) — 2018-10-08
- 1.0.3 — 2018-10-08
- 1.0.2 — 2018-10-07
- 1.0.1 — 2018-10-07
- 1.0.0 — 2018-10-07

## README

<div align="center">
<br>
<img src="https://github.com/etienne-dldc/overmind-plugin/blob/master/assets/logo.svg" width="600px">
<br>
</div>

# Overmind Plugin

A plugin system for [overmind](https://www.overmindjs.org/) allowing deeply nested `state`, `actions`, `reactions`, `effects` and `onInitialize`.

```
npm install overmind-plugin
```

## Usage

```js
import { resolvePlugins } from 'overmind-plugin';
import App from 'overmind';

const config = {
  state: {
    /* ... */
  },
  actions: {
    /* ... */
  },
};

const app = new App(resolvePlugins(config));
```

Now your `config` support a new `plugins` field where you can put nested config:

```js
import { plugin } from 'overmind-plugin';

const config = {
  state: { foo: 'bar' },
  actions: { doStuff: actions.doStuff }
  plugins: {
    firstPlugin: plugin({
      state: { isPlugin: true },
      actions: { doStuffFromPlugin: actions.doStuffFromPlugin }
    })
  }
}
```

...is the same as

```js
const config = {
  state: {
    foo: 'bar',
    firstPlugin: {
      isPlugin: true,
    },
  },
  actions: {
    doStuff: actions.doStuff,
    firstPlugin: {
      doStuffFromPlugin: actions.doStuffFromPlugin,
    },
  },
};
```

## Deep plugins

Plugins don't have to be at the first level of `plugins` they can be as deep as you want. Just remember to wrap your plugin config a a `plugin()` call to identify what is a plugin and what is just structure:

```js
const config = {
  plugins: {
    admin: {
      dashboard: plugin(dashboardConfig),
    },
    user: plugin(userConfig),
  },
};
```

## Nested plugins

The config passed to `plugin()` also support a `plugins` field so you can do:

```js
const config = {
  plugins: {
    admin: plugin({
      state: {},
      plugins: {
        dashboard: plugin(dashboardConfig),
      },
    }),
  },
};
```

## Dynamic plugins

The `plugin()` function can accept a function instead of an object. This function will receive the `path` where the plugin is as an array of strings:

```js
const myPlugin = plugin(path => {
  return {
    state: {},
    actions: {},
  };
});

const config = {
  plugins: {
    admin: {
      dashboard: myPlugin, // path will be ['admin', 'dashboard']
    },
    user: myPlugin, // path will be ['user']
  },
};
```

## Plugin factory

You can easily abtract logic with a plugin factory:

```js
const myPluginFactory = options =>
  plugin(path => {
    return {
      state: {},
      actions: {},
    };
  });

const config = {
  plugins: {
    admin: {
      dashboard: myPluginFactory({}),
    },
    user: myPluginFactory({}),
  },
};
```

## External library

You can publish your plugin factory as a package so other can use it too. All you have to do is document how to support `plugins` with overmind.

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