Skip to content

Commit

Permalink
feat: hoodie.plugin
Browse files Browse the repository at this point in the history
Adding a method to add 'plugins' to hoodie object. Plugins can be passed as a
function (a callback that will recieve hoodie as a parameter) or an object (the
key will be the method name, and the value is the function). Plugin calls can be
chained to add multiple plugins. See README.md for examples.

closes #2
  • Loading branch information
nathanstilwell authored and gr2m committed Dec 1, 2015
1 parent 3545989 commit a12d793
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function Hoodie (options) {
api.task = new Task('/hoodie/task/api')
api.connectionStatus = new ConnectionStatus(api.url)
api.log = new Log('hoodie')
api.plugin = require('./lib/plugin')

api.on = require('./lib/events').on.bind(this, state)
api.one = require('./lib/events').one.bind(this, state)
Expand Down
15 changes: 15 additions & 0 deletions lib/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = function pluginMethod (plugin) {
var self = this

if (typeof plugin === 'function') {
plugin(self)
}

if (typeof plugin === 'object') {
Object.keys(plugin).forEach(function (key) {
self[key] = plugin[key]
})
}

return self
}

0 comments on commit a12d793

Please sign in to comment.