git ssb

16+

Dominic / patchbay



Tree: f10d4f05f93f10bbe4bfbb914a054e6332171721

Files: f10d4f05f93f10bbe4bfbb914a054e6332171721 / modules_core / suggest-box.js

1053 bytesRaw
1const fs = require('fs')
2const h = require('../h')
3const onload = require('on-load')
4const { para } = require('cont')
5const Suggest = require('suggest-box')
6
7exports.needs = {}
8
9exports.gives = {
10 build_suggest_box: true,
11 css: true
12}
13
14exports.create = function (api) {
15 return {
16 build_suggest_box,
17 css: () => fs.readFileSync(__filename.replace(/js$/, 'css'), 'utf8') // NOTE css
18 }
19
20 function build_suggest_box (inputNode, asyncSuggesters, opts = {}) {
21 function suggester (inputText, cb) {
22 para(asyncSuggesters(inputText))
23 ((err, ary) => {
24 if(err) return cb(err)
25
26 var suggestions = ary.filter(Boolean).reduce((a, b) => a.concat(b), [])
27 cb(null, suggestions)
28 })
29 }
30
31 var suggestBox
32 onload(inputNode, (el) => {
33 suggestBox = Suggest(el, suggester, opts)
34 })
35
36 // HACK (mix) : onload is needed because Suggest demands a parent node.
37 // I've chosen this over forcing users to pass a callback
38 return {
39 complete: () => suggestBox.complete()
40 }
41 }
42}
43
44

Built with git-ssb-web