forked from mmckegg/loop-drop-remote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (43 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var View = require('rincewind')
var become = require('become')
var jsonQuery = require('json-query')
var EventEmitter = require('events').EventEmitter
var behave = require('./behaviors')
/// the main view
var render = View(__dirname + '/remotelist.html')
module.exports = function(element, audioContext){
// var audioContext = Object.create(parentAudioContext)
var self = audioContext.createGain()
// audioContext.loadSample = function(src, cb){
// }
var updateBehaviors = behave(element)
var context = {
audioContext: audioContext,
get: getValue,
refresh: refresh,
data: {
remote: null
},
source: null
}
element.context = context
function getValue(query, source){
if (source != null){
var context = Object.create(this)
context.parentContext = this
context.source = source
return jsonQuery(query, context).value
} else {
return jsonQuery(query, this).value
}
}
function refresh(){
var newContent = render(context)
become(element, newContent, {inner: true, onChange: updateBehaviors, tolerance: 0})
}
refresh()
return self
}
function obtain(obj){
return JSON.parse(JSON.stringify(obj))
}