1.0.1 • Published 8 years ago

oc-hobknob v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

oc-hobknob Build Status

OpenComponents plugin for interacting with Hobknob toggles inside OC components.

Requirements:

  • Node version: min: 0.10.40, recommended: >=4.2.X
  • OC registry
  • Hobknob server

Install

npm i oc-hobknob --save

Registry setup

More info about integrating OC plugins: here

...
var registry = new oc.registry(configuration);

registry.register({
  name: 'getToggle',
  register: require('oc-hobknob'),
  options: {
    host: 'hobknob-etcd.hosts.com',
    errorHandler: function(err){
      console.log(err);
    }
  }
}, function(err){
  if(err){
    console.log('plugin initialisation failed:', err);
  } else {
    console.log('hobknob now available');
  }
});

...

registry.start(callback);

Using it inside components

Example for a components' server.js:

module.exports.data = function(context, callback){
  callback(null, {
    showSomething: context.plugins.getToggle('myApp', 'toggleName', false)
  });
};

API

####Api for plugin setup:

parametertypemandatorydescription
errorHandlerfunctionnoThe error handler
hoststringyesThe hobknob etcd host
portnumbernoDefault 4001, the etcd port
syncIntervalnumber (ms)noDefault 30000, time for the internal cache to refresh

Api for plugin usage:

The plugin name is declared when initialising a plugin. Following assumes getToggle is the designated name.

context.plugins.getToggle(serviceName, toggleName)

Syncronous function that gets a value for a given Service name and toggle. Default for when hobknob doesn't have the value is false.

context.plugins.getToggle(serviceName, toggleName, defaultValue)

Syncronous function that gets a value for a given Service name and toggle. Default for when hobknob doesn't have the value is false.

context.plugins.getToggle(serviceName, toggleName, secondaryToggleKey, defaultValue)

Syncronous function that gets an Hobknob toggle value for a given serviceName and toggleName and secondaryToggleKey using specified default value.

Contributing

Yes please. Open an issue first.

License

MIT