Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit 83c8c21

Browse files
Merge pull request #718 from xgrommx/patch-3
Update partition.md
2 parents 94fe363 + a938199 commit 83c8c21

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

doc/api/core/operators/partition.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,36 @@ let subscription2 = odds.subscribe(
4747
// => Completed
4848
```
4949

50+
#### Example
51+
52+
```html
53+
<div id="dom-event-source"></div>
54+
<div id="dom-event-output">
55+
<div class="left"><p></p></div>
56+
<div class="right"><p></p></div>
57+
</div>
58+
```
59+
60+
```js
61+
var sourceElement = document.getElementById("dom-event-source");
62+
var elements = ["#dom-event-output .left p", "#dom-event-output .right p"].map(document.querySelector.bind(document));
63+
var elementRect = sourceElement.getBoundingClientRect();
64+
65+
var observers = Rx.Observable.fromEvent(sourceElement, 'mousemove')
66+
.map(e => ({
67+
x: Math.floor(e.clientX - elementRect.left),
68+
y: Math.floor(e.clientY - elementRect.top)
69+
})
70+
).partition(pos => pos.x < sourceElement.clientWidth / 2);
71+
72+
elements.forEach((n, i, a) =>
73+
observers[i].subscribe(displayCoordinates.bind(displayCoordinates, n)));
74+
75+
function displayCoordinates(element, pos) {
76+
element.textContent = `(x: ${pos.x}, y: ${pos.y})`;
77+
}
78+
```
79+
5080
### Location
5181

5282
File:

0 commit comments

Comments
 (0)