|
24 | 24 | disposableEmpty = Rx.Disposable.empty, |
25 | 25 | slice = Array.prototype.slice, |
26 | 26 | proto = $.fn; |
| 27 | + |
| 28 | + function observableCreateRefCount(subscribe) { |
| 29 | + return observableCreate(subscribe).publish().refCount(); |
| 30 | + } |
27 | 31 | // Check for deferred as of jQuery 1.5 |
28 | 32 | if ($.Deferred) { |
29 | 33 | /** |
|
88 | 92 | */ |
89 | 93 | proto.onAsObservable = function () { |
90 | 94 | var parent = this, args = slice.call(arguments, 0); |
91 | | - return observableCreate(function(observer) { |
| 95 | + return observableCreateRefCount(function(observer) { |
92 | 96 |
|
93 | 97 | function handler(eventObject) { |
94 | 98 | eventObject.additionalArguments = slice.call(arguments, 1); |
|
102 | 106 | return function() { |
103 | 107 | parent.off.apply(parent, args); |
104 | 108 | }; |
105 | | - }).publish().refCount(); |
| 109 | + }); |
106 | 110 | }; |
107 | 111 | } |
108 | 112 |
|
|
115 | 119 | */ |
116 | 120 | proto.bindAsObservable = function(eventType, eventData) { |
117 | 121 | var parent = this; |
118 | | - return observableCreate(function(observer) { |
| 122 | + return observableCreateRefCount(function(observer) { |
119 | 123 |
|
120 | 124 | function handler(eventObject) { |
121 | 125 | eventObject.additionalArguments = slice.call(arguments, 1); |
|
127 | 131 | return function() { |
128 | 132 | parent.unbind(eventType, eventData, handler); |
129 | 133 | }; |
130 | | - }).publish().refCount(); |
| 134 | + }); |
131 | 135 | }; |
132 | 136 |
|
133 | 137 | /** |
|
140 | 144 | */ |
141 | 145 | proto.delegateAsObservable = function(selector, eventType, eventData) { |
142 | 146 | var parent = this; |
143 | | - return observableCreate(function(observer) { |
| 147 | + return observableCreateRefCount(function(observer) { |
144 | 148 |
|
145 | 149 | function handler(eventObject) { |
146 | 150 | eventObject.additionalArguments = slice.call(arguments, 1); |
|
152 | 156 | return function() { |
153 | 157 | parent.undelegate(selector, eventType, handler); |
154 | 158 | }; |
155 | | - }).publish().refCount(); |
| 159 | + }); |
156 | 160 | }; |
157 | 161 |
|
158 | 162 | // Removed as of 1.9 |
|
166 | 170 | */ |
167 | 171 | proto.liveAsObservable = function(eventType, data) { |
168 | 172 | var parent = this; |
169 | | - return observableCreate(function(observer) { |
| 173 | + return observableCreateRefCount(function(observer) { |
170 | 174 |
|
171 | 175 | function handler(eventObject) { |
172 | 176 | eventObject.additionalArguments = slice.call(arguments, 1); |
|
178 | 182 | return function() { |
179 | 183 | parent.die(eventType, data, handler); |
180 | 184 | }; |
181 | | - }).publish().refCount(); |
| 185 | + }); |
182 | 186 | }; |
183 | 187 | } |
184 | 188 |
|
|
454 | 458 |
|
455 | 459 | jQueryProto[method](options); |
456 | 460 |
|
457 | | - return subject; |
| 461 | + return subject.asObservable(); |
458 | 462 | } |
459 | 463 |
|
460 | 464 | /** |
|
527 | 531 |
|
528 | 532 | this.animate(properties, options); |
529 | 533 |
|
530 | | - return subject; |
| 534 | + return subject.asObservable(); |
531 | 535 | }; |
532 | 536 |
|
533 | 537 | /** |
|
563 | 567 | subject.onCompleted(); |
564 | 568 | }); |
565 | 569 |
|
566 | | - return subject; |
| 570 | + return subject.asObservable(); |
567 | 571 | }; |
568 | 572 |
|
569 | 573 | /** |
|
0 commit comments