From 10b39c36fa25a287a1feb58a4aebdd9f942cf8c0 Mon Sep 17 00:00:00 2001 From: Paolo Moretti Date: Mon, 26 Feb 2018 17:00:04 +0000 Subject: [PATCH] Revert https://github.com/JedWatson/react-hammerjs/pull/64 and use `findDOMNode` to get the component reference --- dist/react-hammerjs.es.js | 11 ++--------- dist/react-hammerjs.js | 18 +++++------------- dist/react-hammerjs.min.js | 2 +- lib/Hammer.js | 12 +++--------- package.json | 3 ++- src/Hammer.js | 11 ++--------- 6 files changed, 15 insertions(+), 42 deletions(-) diff --git a/dist/react-hammerjs.es.js b/dist/react-hammerjs.es.js index b25fc96..9524ef1 100644 --- a/dist/react-hammerjs.es.js +++ b/dist/react-hammerjs.es.js @@ -1,5 +1,6 @@ import PropTypes from 'prop-types'; import React from 'react'; +import { findDOMNode } from 'react-dom'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); @@ -117,7 +118,7 @@ var HammerComponent = function (_React$Component) { _createClass(HammerComponent, [{ key: 'componentDidMount', value: function componentDidMount() { - this.hammer = new Hammer(this.domElement); + this.hammer = new Hammer(findDOMNode(this)); updateHammer(this.hammer, this.props); } }, { @@ -147,14 +148,6 @@ var HammerComponent = function (_React$Component) { } }, this); - var self = this; - props.ref = function (domElement) { - if (self.props.ref) { - self.props.ref(domElement); - } - self.domElement = domElement; - }; - // Reuse the child provided // This makes it flexible to use whatever element is wanted (div, ul, etc) return React.cloneElement(React.Children.only(this.props.children), props); diff --git a/dist/react-hammerjs.js b/dist/react-hammerjs.js index 4b6127d..f069803 100644 --- a/dist/react-hammerjs.js +++ b/dist/react-hammerjs.js @@ -1,8 +1,8 @@ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('prop-types'), require('react')) : - typeof define === 'function' && define.amd ? define(['prop-types', 'react'], factory) : - (global.Hammer = factory(global.PropTypes,global.React)); -}(this, (function (PropTypes,React) { 'use strict'; + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('prop-types'), require('react'), require('react-dom')) : + typeof define === 'function' && define.amd ? define(['prop-types', 'react', 'react-dom'], factory) : + (global.Hammer = factory(global.PropTypes,global.React,global.ReactDOM)); +}(this, (function (PropTypes,React,reactDom) { 'use strict'; PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes; React = React && React.hasOwnProperty('default') ? React['default'] : React; @@ -123,7 +123,7 @@ var HammerComponent = function (_React$Component) { _createClass(HammerComponent, [{ key: 'componentDidMount', value: function componentDidMount() { - this.hammer = new Hammer(this.domElement); + this.hammer = new Hammer(reactDom.findDOMNode(this)); updateHammer(this.hammer, this.props); } }, { @@ -153,14 +153,6 @@ var HammerComponent = function (_React$Component) { } }, this); - var self = this; - props.ref = function (domElement) { - if (self.props.ref) { - self.props.ref(domElement); - } - self.domElement = domElement; - }; - // Reuse the child provided // This makes it flexible to use whatever element is wanted (div, ul, etc) return React.cloneElement(React.Children.only(this.props.children), props); diff --git a/dist/react-hammerjs.min.js b/dist/react-hammerjs.min.js index 2c15426..76623b7 100644 --- a/dist/react-hammerjs.min.js +++ b/dist/react-hammerjs.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("prop-types"),require("react")):"function"==typeof define&&define.amd?define(["prop-types","react"],t):e.Hammer=t(e.PropTypes,e.React)}(this,function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){t.hasOwnProperty("vertical")&&console.warn("vertical is deprecated, please use `direction` instead");var n=t.direction;if(n||t.hasOwnProperty("vertical")){var o=n||(t.vertical?"DIRECTION_ALL":"DIRECTION_HORIZONTAL");e.get("pan").set({direction:c[o]}),e.get("swipe").set({direction:c[o]})}t.options&&Object.keys(t.options).forEach(function(n){if("recognizers"===n)Object.keys(t.options.recognizers).forEach(function(n){var o=e.get(n);o.set(t.options.recognizers[n]),t.options.recognizers[n].requireFailure&&o.requireFailure(t.options.recognizers[n].requireFailure)},this);else{var o={};o[n]=t.options[n],e.set(o)}},this),t.recognizeWith&&Object.keys(t.recognizeWith).forEach(function(n){e.get(n).recognizeWith(t.recognizeWith[n])},this),Object.keys(t).forEach(function(n){var o=p[n];o&&(e.off(o),e.on(o,t[n]))})}e=e&&e.hasOwnProperty("default")?e.default:e,t=t&&t.hasOwnProperty("default")?t.default:t;var a=function(){function e(e,t){for(var n=0;n= 0.14.9 < 17.0.0", + "react-dom": ">= 0.14.9 < 17.0.0" }, "scripts": { "build": "npm run build:clean && npm run build:lib && npm run build:dist", diff --git a/src/Hammer.js b/src/Hammer.js index 22ea632..d62bdad 100644 --- a/src/Hammer.js +++ b/src/Hammer.js @@ -1,5 +1,6 @@ import PropTypes from 'prop-types'; import React from 'react'; +import { findDOMNode } from 'react-dom' // require('hammerjs') when in a browser. This is safe because Hammer is only // invoked in componentDidMount, which is not executed on the server. @@ -109,7 +110,7 @@ export default class HammerComponent extends React.Component { }; componentDidMount() { - this.hammer = new Hammer(this.domElement); + this.hammer = new Hammer(findDOMNode(this)); updateHammer(this.hammer, this.props); } @@ -136,14 +137,6 @@ export default class HammerComponent extends React.Component { } }, this); - var self = this; - props.ref = function(domElement) { - if (self.props.ref) { - self.props.ref(domElement); - } - self.domElement = domElement; - }; - // Reuse the child provided // This makes it flexible to use whatever element is wanted (div, ul, etc) return React.cloneElement(React.Children.only(this.props.children), props);