import React from 'react';
import Rx from 'rx';

var dom = {};
['touchstart', 'touchmove', 'touchend'].forEach(ev => {
  dom[ev] = (element, selector) => Rx.Observable.fromEvent(element, ev, selector)
});

function eventPreventDefault(event) {
  event.preventDefault();
}

function hasTwoTouchPoints(event) {
  return event.touches && event.touches.length === 2;
}

function logger(subject) {
  console.log(subject);
}

class Pinch extends React.Component {
  constructor(props) {
    super(props);
    this.state = { scale: 1 };
  }

  componentWillMount() {
    this.handlePinch();
  }

  handlePinch() {
    let touchStart = dom.touchstart(window);
    let touchMove = dom.touchmove(window);
    let touchEnd = dom.touchend(window);

    let pinch = touchStart
      .tap(eventPreventDefault)
      .takeWhile(hasTwoTouchPoints)
      .flatMap(() => {
        return touchMove
          .pluck('scale')
          .takeUntil(touchEnd)
      })
      .tap(logger)

    pinch.subscribe(scale => this.setState({ scale: scale }));
  }

  render() {
    return (
      <div>
        {this.props.render(this.state.scale)}
      </div>
    );
  }
}

Pinch.propTypes = { render: React.PropTypes.func };

export default Pinch;

@@ -46,22 +46,18 @@
 ';%0A%0A
-var
+let
  dom = 
-%7B%7D;%0A
 %5B'to
@@ -96,18 +96,27 @@
 d'%5D.
-forEach(ev
+reduce((dom, event)
  =%3E 
@@ -125,16 +125,19 @@
   dom%5Bev
+ent
 %5D = (ele
@@ -190,16 +190,19 @@
 ment, ev
+ent
 , select
@@ -204,17 +204,36 @@
 elector)
-%0A
+;%0A  return dom;%0A%7D, %7B
 %7D);%0A%0Afun

Update Pinch.js for more idiomatic ES6