Scuttle-inject
Takes a particular sort of nested tree of methods and returns a version of that tree which has a scuttlebutt server injected into each method.
This pattern means you only need to inject a scuttlebot once, makes it easier to test your methods, and handles being able to inject different sorts of server for you.
Example usage
// methods.jsmoduleexports = async: { return { // check the opts before publishing const cleanOpts = server } } // getPoll: (key, cb) => {} pull: { return { const defaultQuery = ... const query = Object return serverquery } } // openPolls: (opts) => {}, // closedPolls: (opts) => {}
Injecting server once (somehwhere high-level):
const inject = cosnt methods = const scuttle = // assume you're in a context where you have a server
Using the scuttle helper:
const opts = { ... }
scuttle.async.publishPoll(opts, cb)
API
inject(server, methods, pluginDeps)
-
server
- ascuttlebot
server, anssb-client
connection to a server, or an observeable which will resolve into a server connection (such as Patchcore'ssbot.obs.connection
) -
methods
- an Object nested at least 2 levels deep, where there must be one layer which specifies thetype
of method. Valid types are :sync
,async
,pull
,obs
-
pluginDeps
(optional) - an Array of plugins apis the scuttlebot must have for your methods to work. e.g.['query']
will check thatsbot.query
has methods which are accessible.