-
Notifications
You must be signed in to change notification settings - Fork 1
/
backbacon.js
46 lines (41 loc) · 1.3 KB
/
backbacon.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
(function(){
var _Bacon;
var _Backbone;
if (typeof require !== 'undefined') {
_Bacon = require('baconjs').Bacon;
_Backbone = require('backbone');
} else {
_Bacon = Bacon;
_Backbone = Backbone;
}
__slice = [].slice;
next = function(value) {
return new _Bacon.Next(_Bacon._.always(value));
};
_Backbone.Model.prototype.asEventStream = function(eventName, eventTransformer) {
var element;
if (typeof eventTransformer === 'undefined' || eventTransformer === null ) {
eventTransformer = _Bacon._.id;
}
model = this;
return new _Bacon.EventStream(function(sink) {
var handler, unbind;
handler = function() {
var args, reply;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
reply = sink(next(eventTransformer.apply(null, args)));
if (reply === _Bacon.noMore) {
return unbind();
}
};
unbind = function() {
return model.off(eventName, handler);
};
model.on(eventName, handler);
return unbind;
});
};
if (typeof module !== 'undefined') {
module.exports = _Backbone;
}
}).call(this);