-
Notifications
You must be signed in to change notification settings - Fork 0
/
PropertyStream.js
37 lines (34 loc) · 1.05 KB
/
PropertyStream.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
/* UMD.define */ (typeof define=="function"&&define||function(d,f,m){m={module:module,require:require};module.exports=f.apply(null,d.map(function(n){return m[n]||require(n)}))})
(["./EventSource", "./EventSink", "dcl"], function(EventSource, EventSink, dcl){
"use strict";
var Value = EventSource.Value;
return dcl(EventSink, {
declaredClass: "events/PropertyStream",
constructor: function(){
this.micro.callback = makeCallback(this);
},
on: dcl.superCall(function(sup){
return function on(channelName, callback, errback, stopback){
var result = sup.apply(this, arguments);
if((typeof channelName != "string" || channelName == "default") && this.lastValue){
result.micro.send(this.lastValue);
}
return result;
};
}),
getValue: function getValue(){
return this.lastValue && this.lastValue.x;
},
isValueAvailable: function isValueAvailable(){
return !!this.lastValue;
}
});
function makeCallback(stream){
return function(val){
if(val instanceof Value){
stream.lastValue = val;
}
return val;
};
}
});