0.1.9 • Published 8 years ago
reliable-plugin v0.1.9
reliable-plugin
reliable plugin for reliable-master.
Install
npm install reliable-plugin
Usage
app.views
app.views is a Map object.
app.get('/path/index', function *() {
this.app.views.get('layout')
})
app.addPluginI18n
// index.js
app.get('/path/index', functino *() {
const app = this.app
const locale = app._options.locale
app.addPluginI18n(locale, require(`./resources/i18n/${locale}`))
})
// resources/i18n/en-US.js
module.exports = {
key: value
}
app.addEventListener
slave means reliable-save
support event:
lostSlave
: when a slave disconnectslaveOnline
: slave onlinetaskEnd
: a task endtaskFailed
: task end and failed, but doesn't dispatch taskEnd event
app.addEventListener('lostSlave', data => {})
app.addEventListener('lostSlave', data => {
}, {
isOnce: true, // only trigger once
scope: null // the scope where the callback is defined
})
app.removeEventListener
const func = () => {}
app.addEventListener('lostSlave', func)
app.removeEventListener('lostSlave', func)
// ---------- or -------------
app.addEventListener('lostSlave', func, { id: 'xxx' })
app.removeEventListener('lostSlave', xxx)
app.registeCollection
registe a plugin collection
app.registeCollection({
name: 'slack', // plugin name, should be unique
url: '', // optional, auto add prefix `/plugin`
data: {
channel: []
}
})
app.getDB
const pluginModel = app.getDB()
pluginModel
.getDataByName('slack')
.then(data => {
conosle.log(data)
})
app.getTaskDB
const taskModel = app.getTaskDB()
taskModel
.getByProjectId('project id')
.then(data => {
conosle.log(data)
})
app.configMail
const mail = app.configMail({
locale: 'zh-CN',
mail: {},
site: {}
})
mail.sendTaskEndMail('your.email@address', data, info => {
conosle.log(info)
})
more detail, see reliable-mail