|
| 1 | +### `Rx.DOM.from(url, [openObserver])` |
| 2 | +[Ⓢ](https://github.com/Reactive-Extensions/RxJS-DOM/blob/master/src/eventsource.js "View in source") |
| 3 | + |
| 4 | +This method wraps an EventSource as an observable sequence which is used to send server-side events. Note that your browser must support EventSource objects. |
| 5 | + |
| 6 | +#### Arguments |
| 7 | +1. `url` *(String)*: The URL of the Server-Side Events. |
| 8 | +3. `[openObserver]` *(`Rx.Observer`)*: An optional Observer to capture the open event. |
| 9 | + |
| 10 | +#### Returns |
| 11 | +*(`Observable`)*: An observable sequence which represents the data from a server-side event. |
| 12 | + |
| 13 | +#### Example |
| 14 | +```js |
| 15 | +// Using a function for the open |
| 16 | +var source = Rx.DOM.fromEventSource('foo.php'); |
| 17 | + |
| 18 | +source.subscribe(function (e) { |
| 19 | + console.log('Received data: ' + e.data); |
| 20 | +}); |
| 21 | + |
| 22 | + |
| 23 | +// Using an observer for the open |
| 24 | +var observer = Rx.Observer.create(function (e) { |
| 25 | + console.log('Opening'); |
| 26 | +}); |
| 27 | + |
| 28 | +// Using a function for the open |
| 29 | +var source = Rx.DOM.fromEventSource('foo.php', observer); |
| 30 | + |
| 31 | +socket.subscribe(function (e) { |
| 32 | + console.log('Received data: ' + e.data); |
| 33 | +}); |
| 34 | + |
| 35 | +socket.onNext('data'); |
| 36 | +``` |
| 37 | + |
| 38 | +### Location |
| 39 | + |
| 40 | +File: |
| 41 | +- [`/src/eventsource.js`](https://github.com/Reactive-Extensions/RxJS-DOM/blob/master/src/eventsource.js) |
| 42 | + |
| 43 | +Dist: |
| 44 | +- [`rx.dom.js`](https://github.com/Reactive-Extensions/RxJS-DOM/blob/master/dist/rx.dom.js) | - [`rx.dom.compat.js`](https://github.com/Reactive-Extensions/RxJS-DOM/blob/master/dist/rx.dom.compat.js) |
| 45 | + |
| 46 | +Prerequisites: |
| 47 | +- If using `rx.js` |
| 48 | + - [`rx.js`](https://github.com/Reactive-Extensions/RxJS/blob/master/dist/rx.js) | [`rx.compat.js`](https://github.com/Reactive-Extensions/RxJS/blob/master/dist/rx.compat.js) |
| 49 | + - [`rx.binding.js`](https://github.com/Reactive-Extensions/RxJS/blob/master/dist/rx.binding.js) |
| 50 | +- [`rx.lite.js`](https://github.com/Reactive-Extensions/RxJS/blob/master/rx.lite.js) | [`rx.lite.compat.js`](https://github.com/Reactive-Extensions/RxJS/blob/master/rx.lite.compat.js) |
| 51 | + |
| 52 | +NPM Packages: |
| 53 | +- [`rx-dom`](https://preview.npmjs.com/package/rx-dom) |
| 54 | + |
| 55 | +NuGet Packages: |
| 56 | +- [`RxJS-Bridges-HTML`](http://www.nuget.org/packages/RxJS-Bridges-HTML/) |
| 57 | + |
| 58 | +Unit Tests: |
| 59 | +- [`/tests/tests.eventsource.js](https://github.com/Reactive-Extensions/RxJS-DOM/blob/master/tests/tests.eventsource.js) |
0 commit comments