Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit d496bab

Browse files
committed
Rigth way to get if isValid
1 parent 2c2c7b4 commit d496bab

File tree

3 files changed

+290
-8
lines changed

3 files changed

+290
-8
lines changed

dist/react-nice-input-password.js

Lines changed: 285 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ var _InputLabel = __webpack_require__(14);
534534

535535
var _InputLabel2 = _interopRequireDefault(_InputLabel);
536536

537+
var _timers = __webpack_require__(15);
538+
537539
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
538540

539541
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -622,17 +624,17 @@ var NiceInputPassword = function (_React$Component) {
622624
function handleChange(event) {
623625
var target = event.target;
624626

625-
627+
var levels = this.handleValidateAndGetLevels(target.value);
626628
this.setState({
627-
levels: this.handleValidateAndGetLevels(target.value)
629+
levels: levels
628630
});
629631

630632
this.props.onChange({
631633
name: this.props.name,
632634
value: target.value,
633-
isValid: this.state.levels.filter(function (level) {
635+
isValid: levels.filter(function (level) {
634636
return level.isValid;
635-
}).length === this.state.levels.length
637+
}).length === levels.length
636638
});
637639
}
638640

@@ -1601,6 +1603,285 @@ InputLabel.defaultProps = defaultProps;
16011603

16021604
exports['default'] = InputLabel;
16031605

1606+
/***/ }),
1607+
/* 15 */
1608+
/***/ (function(module, exports, __webpack_require__) {
1609+
1610+
var apply = Function.prototype.apply;
1611+
1612+
// DOM APIs, for completeness
1613+
1614+
exports.setTimeout = function() {
1615+
return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
1616+
};
1617+
exports.setInterval = function() {
1618+
return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
1619+
};
1620+
exports.clearTimeout =
1621+
exports.clearInterval = function(timeout) {
1622+
if (timeout) {
1623+
timeout.close();
1624+
}
1625+
};
1626+
1627+
function Timeout(id, clearFn) {
1628+
this._id = id;
1629+
this._clearFn = clearFn;
1630+
}
1631+
Timeout.prototype.unref = Timeout.prototype.ref = function() {};
1632+
Timeout.prototype.close = function() {
1633+
this._clearFn.call(window, this._id);
1634+
};
1635+
1636+
// Does not start the time, just sets up the members needed.
1637+
exports.enroll = function(item, msecs) {
1638+
clearTimeout(item._idleTimeoutId);
1639+
item._idleTimeout = msecs;
1640+
};
1641+
1642+
exports.unenroll = function(item) {
1643+
clearTimeout(item._idleTimeoutId);
1644+
item._idleTimeout = -1;
1645+
};
1646+
1647+
exports._unrefActive = exports.active = function(item) {
1648+
clearTimeout(item._idleTimeoutId);
1649+
1650+
var msecs = item._idleTimeout;
1651+
if (msecs >= 0) {
1652+
item._idleTimeoutId = setTimeout(function onTimeout() {
1653+
if (item._onTimeout)
1654+
item._onTimeout();
1655+
}, msecs);
1656+
}
1657+
};
1658+
1659+
// setimmediate attaches itself to the global object
1660+
__webpack_require__(16);
1661+
exports.setImmediate = setImmediate;
1662+
exports.clearImmediate = clearImmediate;
1663+
1664+
1665+
/***/ }),
1666+
/* 16 */
1667+
/***/ (function(module, exports, __webpack_require__) {
1668+
1669+
/* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) {
1670+
"use strict";
1671+
1672+
if (global.setImmediate) {
1673+
return;
1674+
}
1675+
1676+
var nextHandle = 1; // Spec says greater than zero
1677+
var tasksByHandle = {};
1678+
var currentlyRunningATask = false;
1679+
var doc = global.document;
1680+
var registerImmediate;
1681+
1682+
function setImmediate(callback) {
1683+
// Callback can either be a function or a string
1684+
if (typeof callback !== "function") {
1685+
callback = new Function("" + callback);
1686+
}
1687+
// Copy function arguments
1688+
var args = new Array(arguments.length - 1);
1689+
for (var i = 0; i < args.length; i++) {
1690+
args[i] = arguments[i + 1];
1691+
}
1692+
// Store and register the task
1693+
var task = { callback: callback, args: args };
1694+
tasksByHandle[nextHandle] = task;
1695+
registerImmediate(nextHandle);
1696+
return nextHandle++;
1697+
}
1698+
1699+
function clearImmediate(handle) {
1700+
delete tasksByHandle[handle];
1701+
}
1702+
1703+
function run(task) {
1704+
var callback = task.callback;
1705+
var args = task.args;
1706+
switch (args.length) {
1707+
case 0:
1708+
callback();
1709+
break;
1710+
case 1:
1711+
callback(args[0]);
1712+
break;
1713+
case 2:
1714+
callback(args[0], args[1]);
1715+
break;
1716+
case 3:
1717+
callback(args[0], args[1], args[2]);
1718+
break;
1719+
default:
1720+
callback.apply(undefined, args);
1721+
break;
1722+
}
1723+
}
1724+
1725+
function runIfPresent(handle) {
1726+
// From the spec: "Wait until any invocations of this algorithm started before this one have completed."
1727+
// So if we're currently running a task, we'll need to delay this invocation.
1728+
if (currentlyRunningATask) {
1729+
// Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
1730+
// "too much recursion" error.
1731+
setTimeout(runIfPresent, 0, handle);
1732+
} else {
1733+
var task = tasksByHandle[handle];
1734+
if (task) {
1735+
currentlyRunningATask = true;
1736+
try {
1737+
run(task);
1738+
} finally {
1739+
clearImmediate(handle);
1740+
currentlyRunningATask = false;
1741+
}
1742+
}
1743+
}
1744+
}
1745+
1746+
function installNextTickImplementation() {
1747+
registerImmediate = function(handle) {
1748+
process.nextTick(function () { runIfPresent(handle); });
1749+
};
1750+
}
1751+
1752+
function canUsePostMessage() {
1753+
// The test against `importScripts` prevents this implementation from being installed inside a web worker,
1754+
// where `global.postMessage` means something completely different and can't be used for this purpose.
1755+
if (global.postMessage && !global.importScripts) {
1756+
var postMessageIsAsynchronous = true;
1757+
var oldOnMessage = global.onmessage;
1758+
global.onmessage = function() {
1759+
postMessageIsAsynchronous = false;
1760+
};
1761+
global.postMessage("", "*");
1762+
global.onmessage = oldOnMessage;
1763+
return postMessageIsAsynchronous;
1764+
}
1765+
}
1766+
1767+
function installPostMessageImplementation() {
1768+
// Installs an event handler on `global` for the `message` event: see
1769+
// * https://developer.mozilla.org/en/DOM/window.postMessage
1770+
// * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
1771+
1772+
var messagePrefix = "setImmediate$" + Math.random() + "$";
1773+
var onGlobalMessage = function(event) {
1774+
if (event.source === global &&
1775+
typeof event.data === "string" &&
1776+
event.data.indexOf(messagePrefix) === 0) {
1777+
runIfPresent(+event.data.slice(messagePrefix.length));
1778+
}
1779+
};
1780+
1781+
if (global.addEventListener) {
1782+
global.addEventListener("message", onGlobalMessage, false);
1783+
} else {
1784+
global.attachEvent("onmessage", onGlobalMessage);
1785+
}
1786+
1787+
registerImmediate = function(handle) {
1788+
global.postMessage(messagePrefix + handle, "*");
1789+
};
1790+
}
1791+
1792+
function installMessageChannelImplementation() {
1793+
var channel = new MessageChannel();
1794+
channel.port1.onmessage = function(event) {
1795+
var handle = event.data;
1796+
runIfPresent(handle);
1797+
};
1798+
1799+
registerImmediate = function(handle) {
1800+
channel.port2.postMessage(handle);
1801+
};
1802+
}
1803+
1804+
function installReadyStateChangeImplementation() {
1805+
var html = doc.documentElement;
1806+
registerImmediate = function(handle) {
1807+
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
1808+
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
1809+
var script = doc.createElement("script");
1810+
script.onreadystatechange = function () {
1811+
runIfPresent(handle);
1812+
script.onreadystatechange = null;
1813+
html.removeChild(script);
1814+
script = null;
1815+
};
1816+
html.appendChild(script);
1817+
};
1818+
}
1819+
1820+
function installSetTimeoutImplementation() {
1821+
registerImmediate = function(handle) {
1822+
setTimeout(runIfPresent, 0, handle);
1823+
};
1824+
}
1825+
1826+
// If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
1827+
var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
1828+
attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
1829+
1830+
// Don't get fooled by e.g. browserify environments.
1831+
if ({}.toString.call(global.process) === "[object process]") {
1832+
// For Node.js before 0.9
1833+
installNextTickImplementation();
1834+
1835+
} else if (canUsePostMessage()) {
1836+
// For non-IE10 modern browsers
1837+
installPostMessageImplementation();
1838+
1839+
} else if (global.MessageChannel) {
1840+
// For web workers, where supported
1841+
installMessageChannelImplementation();
1842+
1843+
} else if (doc && "onreadystatechange" in doc.createElement("script")) {
1844+
// For IE 6–8
1845+
installReadyStateChangeImplementation();
1846+
1847+
} else {
1848+
// For older browsers
1849+
installSetTimeoutImplementation();
1850+
}
1851+
1852+
attachTo.setImmediate = setImmediate;
1853+
attachTo.clearImmediate = clearImmediate;
1854+
}(typeof self === "undefined" ? typeof global === "undefined" ? this : global : self));
1855+
1856+
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(17), __webpack_require__(0)))
1857+
1858+
/***/ }),
1859+
/* 17 */
1860+
/***/ (function(module, exports) {
1861+
1862+
var g;
1863+
1864+
// This works in non-strict mode
1865+
g = (function() {
1866+
return this;
1867+
})();
1868+
1869+
try {
1870+
// This works if eval is allowed (see CSP)
1871+
g = g || Function("return this")() || (1,eval)("this");
1872+
} catch(e) {
1873+
// This works if the window reference is available
1874+
if(typeof window === "object")
1875+
g = window;
1876+
}
1877+
1878+
// g can still be undefined, but nothing to do about it...
1879+
// We return undefined, instead of nothing here, so it's
1880+
// easier to handle this case. if(!global) { ...}
1881+
1882+
module.exports = g;
1883+
1884+
16041885
/***/ })
16051886
/******/ ]);
16061887
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-nice-input-password",
3-
"version": "2.1.4",
3+
"version": "2.1.5",
44
"description": "React input password component",
55
"main": "dist/react-nice-input-password.js",
66
"style": "dist/react-nice-input-password.css",

src/NiceInputPassword.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33

44
import './NiceInputPassword.scss';
55
import InputLabel from './components/InputLabel';
6+
import { setTimeout } from 'timers';
67

78
const propTypes = {
89
label: PropTypes.oneOfType([
@@ -75,15 +76,15 @@ class NiceInputPassword extends React.Component {
7576

7677
handleChange(event) {
7778
const { target } = event;
78-
79+
const levels = this.handleValidateAndGetLevels(target.value);
7980
this.setState({
80-
levels: this.handleValidateAndGetLevels(target.value),
81+
levels,
8182
});
8283

8384
this.props.onChange({
8485
name: this.props.name,
8586
value: target.value,
86-
isValid: this.state.levels.filter(level => level.isValid).length === this.state.levels.length,
87+
isValid: levels.filter(level => level.isValid).length === levels.length,
8788
});
8889
}
8990

0 commit comments

Comments
 (0)