From bbe183388a6dd9f1bb790671ac0dc49cefdc2544 Mon Sep 17 00:00:00 2001 From: Konrad Date: Thu, 4 May 2017 12:42:20 +0200 Subject: [PATCH] React 15: Use PropTypes from a separate package (#34) * Use PropTypes from a separate package to accommodate changes in React 15 * Use PropTypes from a separate package to accommodate changes in React 15 * Added PropTypes to the dependencies --- dist/react-notification-system-redux.js | 1037 ++++++++++++++++++- dist/react-notification-system-redux.min.js | 2 +- example/src/components/container.js | 3 +- lib/actions.js | 4 +- lib/notifications.js | 15 +- lib/reducer.js | 9 +- package.json | 3 +- src/notifications.js | 3 +- 8 files changed, 1042 insertions(+), 34 deletions(-) diff --git a/dist/react-notification-system-redux.js b/dist/react-notification-system-redux.js index e134d2e..ce106a6 100644 --- a/dist/react-notification-system-redux.js +++ b/dist/react-notification-system-redux.js @@ -1,4 +1,1005 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.notifications = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + var argIndex = 0; + var message = 'Warning: ' + format.replace(/%s/g, function () { + return args[argIndex++]; + }); + if (typeof console !== 'undefined') { + console.error(message); + } + try { + // --- Welcome to debugging React --- + // This error was thrown as a convenience so that you can use this stack + // to find the callsite that caused this warning to fire. + throw new Error(message); + } catch (x) {} + }; + + warning = function warning(condition, format) { + if (format === undefined) { + throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); + } + + if (format.indexOf('Failed Composite propType: ') === 0) { + return; // Ignore CompositeComponent proptype check. + } + + if (!condition) { + for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { + args[_key2 - 2] = arguments[_key2]; + } + + printWarning.apply(undefined, [format].concat(args)); + } + }; + })(); +} + +module.exports = warning; +},{"./emptyFunction":6}],9:[function(require,module,exports){ +// shim for using process in browser +var process = module.exports = {}; + +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. + +var cachedSetTimeout; +var cachedClearTimeout; + +function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); +} +function defaultClearTimeout () { + throw new Error('clearTimeout has not been defined'); +} +(function () { + try { + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; + } + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; + } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } +} ()) +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch(e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch(e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } + + +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } + + + +} +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} + +function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); +} + +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; +process.prependListener = noop; +process.prependOnceListener = noop; + +process.listeners = function (name) { return [] } + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + +},{}],10:[function(require,module,exports){ Object.defineProperty(exports, "__esModule", { value: true }); @@ -30,8 +1031,8 @@ var _const = require('./const'); // } function show() { - var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - var level = arguments.length <= 1 || arguments[1] === undefined ? 'success' : arguments[1]; + var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'success'; return _extends({ type: _const.RNS_SHOW_NOTIFICATION @@ -68,7 +1069,7 @@ function removeAll() { return { type: _const.RNS_REMOVE_ALL_NOTIFICATIONS }; } -},{"./const":2}],2:[function(require,module,exports){ +},{"./const":11}],11:[function(require,module,exports){ Object.defineProperty(exports, "__esModule", { value: true }); @@ -76,7 +1077,7 @@ var RNS_SHOW_NOTIFICATION = exports.RNS_SHOW_NOTIFICATION = 'RNS_SHOW_NOTIFICATI var RNS_HIDE_NOTIFICATION = exports.RNS_HIDE_NOTIFICATION = 'RNS_HIDE_NOTIFICATION'; var RNS_REMOVE_ALL_NOTIFICATIONS = exports.RNS_REMOVE_ALL_NOTIFICATIONS = 'RNS_REMOVE_ALL_NOTIFICATIONS'; -},{}],3:[function(require,module,exports){ +},{}],12:[function(require,module,exports){ (function (global){ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; @@ -86,6 +1087,10 @@ var _react = (typeof window !== "undefined" ? window['React'] : typeof global != var _react2 = _interopRequireDefault(_react); +var _propTypes = require('prop-types'); + +var _propTypes2 = _interopRequireDefault(_propTypes); + var _actions = require('./actions'); var actions = _interopRequireWildcard(_actions); @@ -185,10 +1190,9 @@ var Notifications = function (_React$Component) { key: 'render', value: function () { function render() { - var _props = this.props; - var notifications = _props.notifications; - - var rest = _objectWithoutProperties(_props, ['notifications']); + var _props = this.props, + notifications = _props.notifications, + rest = _objectWithoutProperties(_props, ['notifications']); return _react2['default'].createElement(_reactNotificationSystem2['default'], _extends({ ref: 'notify' }, rest)); } @@ -201,11 +1205,11 @@ var Notifications = function (_React$Component) { }(_react2['default'].Component); Notifications.propTypes = { - notifications: _react.PropTypes.array + notifications: _propTypes2['default'].array }; Notifications.contextTypes = { - store: _react.PropTypes.object + store: _propTypes2['default'].object }; // Tie actions to Notifications component instance @@ -218,7 +1222,7 @@ Notifications.reducer = _reducer2['default']; module.exports = Notifications; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./actions":1,"./reducer":4,"react-notification-system":undefined}],4:[function(require,module,exports){ +},{"./actions":10,"./reducer":13,"prop-types":4,"react-notification-system":undefined}],13:[function(require,module,exports){ Object.defineProperty(exports, "__esModule", { value: true }); @@ -234,14 +1238,13 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function Notifications() { - var state = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; - var action = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; switch (action.type) { case _const.RNS_SHOW_NOTIFICATION: - var type = action.type; - - var rest = _objectWithoutProperties(action, ['type']); + var type = action.type, + rest = _objectWithoutProperties(action, ['type']); return [].concat(_toConsumableArray(state), [_extends({}, rest, { uid: action.uid })]); case _const.RNS_HIDE_NOTIFICATION: @@ -254,5 +1257,5 @@ function Notifications() { return state; } -},{"./const":2}]},{},[3])(3) +},{"./const":11}]},{},[12])(12) }); \ No newline at end of file diff --git a/dist/react-notification-system-redux.min.js b/dist/react-notification-system-redux.min.js index 4e2718d..a749635 100644 --- a/dist/react-notification-system-redux.min.js +++ b/dist/react-notification-system-redux.min.js @@ -1 +1 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.notifications=e()}}(function(){return function e(t,n,r){function o(u,f){if(!n[u]){if(!t[u]){var c="function"==typeof require&&require;if(!f&&c)return c(u,!0);if(i)return i(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var s=n[u]={exports:{}};t[u][0].call(s.exports,function(e){var n=t[u][1][e];return o(n?n:e)},s,s.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function f(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 c(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)}var a=Object.assign||function(e){for(var t=1;t0&&(o.forEach(function(e){r.indexOf(e.uid)<0&&(console.log("removing",t.system().state.notifications),t.system().removeNotification(e.uid))}),n.forEach(function(e){t.system().addNotification(a({},e,{onRemove:function(){function n(){t.context.store.dispatch(y.hide(e.uid)),e.onRemove&&e.onRemove()}return n}()}))})),this.props.notifications!==n&&0===n.length&&this.system().clearNotifications()}return e}()},{key:"shouldComponentUpdate",value:function(){function e(e){return this.props!==e}return e}()},{key:"render",value:function(){function e(){var e=this.props,t=(e.notifications,i(e,["notifications"]));return p["default"].createElement(_["default"],a({ref:"notify"},t))}return e}()}]),t}(p["default"].Component);N.propTypes={notifications:l.PropTypes.array},N.contextTypes={store:l.PropTypes.object},Object.keys(y).forEach(function(e){N[e]=y[e]}),N.reducer=v["default"],t.exports=N}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./actions":1,"./reducer":4,"react-notification-system":void 0}],4:[function(e,t,n){function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function i(){var e=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];switch(t.type){case f.RNS_SHOW_NOTIFICATION:var n=(t.type,o(t,["type"]));return[].concat(r(e),[u({},n,{uid:t.uid})]);case f.RNS_HIDE_NOTIFICATION:return e.filter(function(e){return e.uid!==t.uid});case f.RNS_REMOVE_ALL_NOTIFICATIONS:return[]}return e}Object.defineProperty(n,"__esModule",{value:!0});var u=Object.assign||function(e){for(var t=1;t1)for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"success";return s({type:l.RNS_SHOW_NOTIFICATION},e,{uid:e.uid||Date.now(),level:n})}function o(e){return r(e,"success")}function i(e){return r(e,"error")}function u(e){return r(e,"warning")}function a(e){return r(e,"info")}function c(e){return{type:l.RNS_HIDE_NOTIFICATION,uid:e}}function f(){return{type:l.RNS_REMOVE_ALL_NOTIFICATIONS}}Object.defineProperty(t,"__esModule",{value:!0});var s=Object.assign||function(e){for(var n=1;n=0||Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}function u(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function a(e,n){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!n||"object"!=typeof n&&"function"!=typeof n?e:n}function c(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function, not "+typeof n);e.prototype=Object.create(n&&n.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),n&&(Object.setPrototypeOf?Object.setPrototypeOf(e,n):e.__proto__=n)}var f=Object.assign||function(e){for(var n=1;n0&&(o.forEach(function(e){r.indexOf(e.uid)<0&&(console.log("removing",n.system().state.notifications),n.system().removeNotification(e.uid))}),t.forEach(function(e){n.system().addNotification(f({},e,{onRemove:function(){function t(){n.context.store.dispatch(h.hide(e.uid)),e.onRemove&&e.onRemove()}return t}()}))})),this.props.notifications!==t&&0===t.length&&this.system().clearNotifications()}return e}()},{key:"shouldComponentUpdate",value:function(){function e(e){return this.props!==e}return e}()},{key:"render",value:function(){function e(){var e=this.props,n=(e.notifications,i(e,["notifications"]));return p["default"].createElement(T["default"],f({ref:"notify"},n))}return e}()}]),n}(p["default"].Component);g.propTypes={notifications:d["default"].array},g.contextTypes={store:d["default"].object},Object.keys(h).forEach(function(e){g[e]=h[e]}),g.reducer=m["default"],n.exports=g}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./actions":10,"./reducer":13,"prop-types":4,"react-notification-system":void 0}],13:[function(e,n,t){function r(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n=0||Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}function i(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};switch(n.type){case a.RNS_SHOW_NOTIFICATION:var t=(n.type,o(n,["type"]));return[].concat(r(e),[u({},t,{uid:n.uid})]);case a.RNS_HIDE_NOTIFICATION:return e.filter(function(e){return e.uid!==n.uid});case a.RNS_REMOVE_ALL_NOTIFICATIONS:return[]}return e}Object.defineProperty(t,"__esModule",{value:!0});var u=Object.assign||function(e){for(var n=1;n 0 && arguments[0] !== undefined ? arguments[0] : {}; + var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'success'; return _extends({ type: _const.RNS_SHOW_NOTIFICATION diff --git a/lib/notifications.js b/lib/notifications.js index 99c3db0..277ee4d 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -6,6 +6,10 @@ var _react = require('react'); var _react2 = _interopRequireDefault(_react); +var _propTypes = require('prop-types'); + +var _propTypes2 = _interopRequireDefault(_propTypes); + var _actions = require('./actions'); var actions = _interopRequireWildcard(_actions); @@ -105,10 +109,9 @@ var Notifications = function (_React$Component) { key: 'render', value: function () { function render() { - var _props = this.props; - var notifications = _props.notifications; - - var rest = _objectWithoutProperties(_props, ['notifications']); + var _props = this.props, + notifications = _props.notifications, + rest = _objectWithoutProperties(_props, ['notifications']); return _react2['default'].createElement(_reactNotificationSystem2['default'], _extends({ ref: 'notify' }, rest)); } @@ -121,11 +124,11 @@ var Notifications = function (_React$Component) { }(_react2['default'].Component); Notifications.propTypes = { - notifications: _react.PropTypes.array + notifications: _propTypes2['default'].array }; Notifications.contextTypes = { - store: _react.PropTypes.object + store: _propTypes2['default'].object }; // Tie actions to Notifications component instance diff --git a/lib/reducer.js b/lib/reducer.js index 75d7aa0..448b6f1 100644 --- a/lib/reducer.js +++ b/lib/reducer.js @@ -13,14 +13,13 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function Notifications() { - var state = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; - var action = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; switch (action.type) { case _const.RNS_SHOW_NOTIFICATION: - var type = action.type; - - var rest = _objectWithoutProperties(action, ['type']); + var type = action.type, + rest = _objectWithoutProperties(action, ['type']); return [].concat(_toConsumableArray(state), [_extends({}, rest, { uid: action.uid })]); case _const.RNS_HIDE_NOTIFICATION: diff --git a/package.json b/package.json index 713d8e4..0777539 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-notification-system-redux", - "version": "1.1.1", + "version": "1.1.2", "description": "react-notification-system-redux", "main": "lib/notifications.js", "author": "Goran Udosic", @@ -44,6 +44,7 @@ "sinon": "^1.17.6" }, "dependencies": { + "prop-types": "^15.5.8", "react-notification-system": "^0.2.x" }, "peerDependencies": { diff --git a/src/notifications.js b/src/notifications.js index fdadc0f..ed1f5b3 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -1,4 +1,5 @@ -import React, {PropTypes} from 'react'; +import React from 'react'; +import PropTypes from 'prop-types'; import * as actions from './actions'; import reducer from './reducer';