mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-10 12:24:20 +01:00
27 lines
705 B
JavaScript
27 lines
705 B
JavaScript
var BoardsAPI = function () {
|
|
this.done = false
|
|
this.fa = []
|
|
this.boards
|
|
require.ensure(['options.jsx', 'ipfs-api', 'boards-api.js'], _ => {
|
|
var opt = require('options.jsx').get()
|
|
var BoardsAPI = require('boards-api.js')
|
|
var ipfs = require('ipfs-api')(opt.addr || 'localhost', opt.port || 5001)
|
|
this.boards = new BoardsAPI(ipfs)
|
|
this.boards.init()
|
|
this.done = true
|
|
this.fa.forEach(fn => fn(this.boards))
|
|
this.fa = undefined
|
|
})
|
|
}
|
|
|
|
BoardsAPI.prototype.use = function (f) {
|
|
if (!f || !f.apply || !f.call) return console.log('Non-function tried to use API:', f)
|
|
if (this.done) {
|
|
f(this.boards)
|
|
} else {
|
|
this.fa.push(f)
|
|
}
|
|
}
|
|
|
|
module.exports = BoardsAPI
|