2015-12-14 00:29:25 +01:00
|
|
|
var BoardsAPI = function () {
|
2015-11-22 00:10:46 +01:00
|
|
|
this.done = false
|
|
|
|
this.fa = []
|
|
|
|
this.boards
|
2015-12-14 00:29:25 +01:00
|
|
|
require.ensure(['options.jsx', 'ipfs-api', 'boards-api.js'], _ => {
|
2015-11-22 00:10:46 +01:00
|
|
|
var opt = require('options.jsx').get()
|
|
|
|
var BoardsAPI = require('boards-api.js')
|
2015-12-14 00:29:25 +01:00
|
|
|
var ipfs = require('ipfs-api')(opt.addr || 'localhost', opt.port || 5001)
|
2015-11-22 00:10:46 +01:00
|
|
|
this.boards = new BoardsAPI(ipfs)
|
|
|
|
this.boards.init()
|
|
|
|
this.done = true
|
|
|
|
this.fa.forEach(fn => fn(this.boards))
|
|
|
|
this.fa = undefined
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-12-14 00:29:25 +01:00
|
|
|
BoardsAPI.prototype.use = function (f) {
|
|
|
|
if (!f || !f.apply || !f.call) return console.log('Non-function tried to use API:', f)
|
|
|
|
if (this.done) {
|
2015-11-22 00:10:46 +01:00
|
|
|
f(this.boards)
|
|
|
|
} else {
|
|
|
|
this.fa.push(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = BoardsAPI
|