# gardr-core-plugin

> The PluginApi and pluginHandler used for both host and ext side plugin functionality

Latest version **0.1.0** (published 2014-06-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install gardr-core-plugin
pnpm add gardr-core-plugin
yarn add gardr-core-plugin
bun add gardr-core-plugin
```

## 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.0 |
| Published | 2014-06-17 |
| First published | 2014-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | FINN.no AS |
| Maintainers | gregersrygg |
| Keywords | gardr, browser |

## Links

- npm: https://www.npmjs.com/package/gardr-core-plugin
- npm.io page: https://npm.io/package/gardr-core-plugin

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2014-06-17
- 0.0.1 — 2014-03-27

## README

gardr-core-plugin
=================

The PluginApi and pluginHandler used for both host and ext side plugin functionality. It has no dependencies to Garðr or
any other libraries.

To make plugins decoupled from the Garðr-code we have plugins as a
[pub-sub](http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern). They are triggered syncronously, so plugins
can change the object that is passed along. In Garðr we use event names like: "{object}:{event}". For instance
"params:parsed" is triggered right after we've parsed the parameters from the URL in gardr-ext. The params object is
passed as the event data. If a plugin needs to change the script URL before it's written, it can just change the value
of `params.url`. Also "item:afterrender" is triggered after an item (banner) has finished loading, and the
item object is passed as the event data.

This module exposes two objects:

    var pluginCore = require('gardr-plugin-core');
    pluginCore.PluginApi; // the API-object constructor
    pluginCore.pluginHandler; // used to register and initialize plugins

It works by exposing a metod that pass plugins to pluginHandler.register. Then call pluginHandler.initPlugins with a new
instance of PluginApi and the options object (if they need it).

    var pluginApi;

    module.exports = {
        plugin: function (pluginFn) {
            pluginCore.pluginHandler.register(pluginFn);
        },

        init: function (options) {
            pluginApi = new pluginCore.PluginApi();
            pluginCore.pluginHandler.initPlugins(pluginApi, options);
        }
    };

Plugin functions have two parameters; pluginApi and options (same options as above).

    module.exports = function (pluginApi, options) {
        // Could check options for plugin configuration or read/change the main module´s options

        pluginApi.on('eventname', function (obj) {
            obj.foo = 'bar';
        });
    };

To trigger events:

    var obj = {foo: null};
    pluginApi.trigger('eventname', obj);
    console.log( obj.foo ); // 'foo'

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