@arco-design/mobile-react 2.38.2 → 2.38.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.en-US.md +2 -2
- package/README.md +2 -2
- package/cjs/action-sheet/index.d.ts +10 -10
- package/cjs/action-sheet/index.js +6 -2
- package/cjs/action-sheet/methods.d.ts +2 -2
- package/cjs/cell/cell.d.ts +1 -1
- package/cjs/cell/cell.js +36 -7
- package/cjs/cell/style/css/index.css +46 -16
- package/cjs/cell/style/index.less +52 -11
- package/cjs/cell/type.d.ts +8 -1
- package/cjs/date-picker/index.d.ts +1 -1
- package/cjs/date-picker/index.js +3 -0
- package/cjs/dialog/index.d.ts +0 -1
- package/cjs/form/form-item.d.ts +5 -4
- package/cjs/form/form-item.js +1 -1
- package/cjs/form/type.d.ts +2 -3
- package/cjs/form/useForm.d.ts +1 -1
- package/cjs/pull-refresh/android-pull-refresh.d.ts +1 -1
- package/cjs/pull-refresh/hooks.d.ts +2 -2
- package/cjs/pull-refresh/ios-pull-refresh.d.ts +1 -1
- package/cjs/pull-refresh/ios-pull-refresh.js +3 -1
- package/cjs/pull-refresh/model.d.ts +0 -1
- package/cjs/stepper/hooks/useValue.d.ts +1 -1
- package/cjs/stepper/type.d.ts +1 -1
- package/cjs/swipe-action/type.d.ts +1 -1
- package/cjs/uploader/upload/upload.d.ts +4 -4
- package/dist/index.js +1337 -1301
- package/dist/index.min.js +4 -4
- package/dist/style.css +33 -8
- package/dist/style.min.css +1 -1
- package/esm/action-sheet/index.d.ts +10 -10
- package/esm/action-sheet/index.js +6 -2
- package/esm/action-sheet/methods.d.ts +2 -2
- package/esm/cell/cell.d.ts +1 -1
- package/esm/cell/cell.js +37 -8
- package/esm/cell/style/css/index.css +46 -16
- package/esm/cell/style/index.less +52 -11
- package/esm/cell/type.d.ts +8 -1
- package/esm/date-picker/index.d.ts +1 -1
- package/esm/date-picker/index.js +3 -0
- package/esm/dialog/index.d.ts +0 -1
- package/esm/form/form-item.d.ts +5 -4
- package/esm/form/form-item.js +5 -5
- package/esm/form/type.d.ts +2 -3
- package/esm/form/useForm.d.ts +1 -1
- package/esm/form/useForm.js +3 -3
- package/esm/pull-refresh/android-pull-refresh.d.ts +1 -1
- package/esm/pull-refresh/android-pull-refresh.js +2 -2
- package/esm/pull-refresh/hooks.d.ts +2 -2
- package/esm/pull-refresh/hooks.js +2 -2
- package/esm/pull-refresh/ios-pull-refresh.d.ts +1 -1
- package/esm/pull-refresh/ios-pull-refresh.js +2 -1
- package/esm/pull-refresh/model.d.ts +0 -1
- package/esm/stepper/hooks/useValue.d.ts +1 -1
- package/esm/stepper/hooks/useValue.js +2 -2
- package/esm/stepper/type.d.ts +1 -1
- package/esm/swipe-action/type.d.ts +1 -1
- package/esm/uploader/upload/upload.d.ts +4 -4
- package/esm/uploader/upload/upload.js +3 -3
- package/esnext/action-sheet/index.d.ts +10 -10
- package/esnext/action-sheet/index.js +7 -3
- package/esnext/action-sheet/methods.d.ts +2 -2
- package/esnext/cell/cell.d.ts +1 -1
- package/esnext/cell/cell.js +19 -3
- package/esnext/cell/style/css/index.css +46 -16
- package/esnext/cell/style/index.less +52 -11
- package/esnext/cell/type.d.ts +8 -1
- package/esnext/date-picker/index.d.ts +1 -1
- package/esnext/date-picker/index.js +5 -0
- package/esnext/dialog/index.d.ts +0 -1
- package/esnext/form/form-item.d.ts +5 -4
- package/esnext/form/form-item.js +11 -6
- package/esnext/form/type.d.ts +2 -3
- package/esnext/form/useForm.d.ts +1 -1
- package/esnext/form/useForm.js +4 -5
- package/esnext/pull-refresh/android-pull-refresh.d.ts +1 -1
- package/esnext/pull-refresh/android-pull-refresh.js +2 -2
- package/esnext/pull-refresh/hooks.d.ts +2 -2
- package/esnext/pull-refresh/hooks.js +3 -3
- package/esnext/pull-refresh/ios-pull-refresh.d.ts +1 -1
- package/esnext/pull-refresh/ios-pull-refresh.js +2 -1
- package/esnext/pull-refresh/model.d.ts +0 -1
- package/esnext/stepper/hooks/useValue.d.ts +1 -1
- package/esnext/stepper/hooks/useValue.js +2 -2
- package/esnext/stepper/type.d.ts +1 -1
- package/esnext/swipe-action/type.d.ts +1 -1
- package/esnext/uploader/upload/upload.d.ts +4 -4
- package/esnext/uploader/upload/upload.js +3 -3
- package/package.json +3 -3
- package/tokens/app/arcodesign/default/css-variables.less +2 -0
- package/tokens/app/arcodesign/default/index.d.ts +2 -0
- package/tokens/app/arcodesign/default/index.js +2 -0
- package/tokens/app/arcodesign/default/index.json +20 -0
- package/tokens/app/arcodesign/default/index.less +2 -0
- package/umd/action-sheet/index.d.ts +10 -10
- package/umd/action-sheet/index.js +6 -2
- package/umd/action-sheet/methods.d.ts +2 -2
- package/umd/cell/cell.d.ts +1 -1
- package/umd/cell/cell.js +36 -7
- package/umd/cell/style/css/index.css +46 -16
- package/umd/cell/style/index.less +52 -11
- package/umd/cell/type.d.ts +8 -1
- package/umd/date-picker/index.d.ts +1 -1
- package/umd/date-picker/index.js +3 -0
- package/umd/dialog/index.d.ts +0 -1
- package/umd/form/form-item.d.ts +5 -4
- package/umd/form/form-item.js +1 -1
- package/umd/form/type.d.ts +2 -3
- package/umd/form/useForm.d.ts +1 -1
- package/umd/pull-refresh/android-pull-refresh.d.ts +1 -1
- package/umd/pull-refresh/hooks.d.ts +2 -2
- package/umd/pull-refresh/ios-pull-refresh.d.ts +1 -1
- package/umd/pull-refresh/ios-pull-refresh.js +5 -5
- package/umd/pull-refresh/model.d.ts +0 -1
- package/umd/stepper/hooks/useValue.d.ts +1 -1
- package/umd/stepper/type.d.ts +1 -1
- package/umd/swipe-action/type.d.ts +1 -1
- package/umd/uploader/upload/upload.d.ts +4 -4
package/dist/index.js
CHANGED
|
@@ -1981,1582 +1981,1582 @@
|
|
|
1981
1981
|
return targetMT;
|
|
1982
1982
|
};
|
|
1983
1983
|
|
|
1984
|
-
var
|
|
1985
|
-
var _extendStatics = function extendStatics(d, b) {
|
|
1986
|
-
_extendStatics = Object.setPrototypeOf || {
|
|
1987
|
-
__proto__: []
|
|
1988
|
-
} instanceof Array && function (d, b) {
|
|
1989
|
-
d.__proto__ = b;
|
|
1990
|
-
} || function (d, b) {
|
|
1991
|
-
for (var p in b) {
|
|
1992
|
-
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
1993
|
-
}
|
|
1994
|
-
};
|
|
1984
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
1995
1985
|
|
|
1996
|
-
|
|
1997
|
-
|
|
1986
|
+
function createCommonjsModule(fn, basedir, module) {
|
|
1987
|
+
return module = {
|
|
1988
|
+
path: basedir,
|
|
1989
|
+
exports: {},
|
|
1990
|
+
require: function (path, base) {
|
|
1991
|
+
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
|
|
1992
|
+
}
|
|
1993
|
+
}, fn(module, module.exports), module.exports;
|
|
1994
|
+
}
|
|
1998
1995
|
|
|
1999
|
-
|
|
2000
|
-
|
|
1996
|
+
function commonjsRequire () {
|
|
1997
|
+
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
1998
|
+
}
|
|
2001
1999
|
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2000
|
+
var es6Promise$1 = createCommonjsModule(function (module, exports) {
|
|
2001
|
+
/*!
|
|
2002
|
+
* @overview es6-promise - a tiny implementation of Promises/A+.
|
|
2003
|
+
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
|
|
2004
|
+
* @license Licensed under MIT license
|
|
2005
|
+
* See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
|
|
2006
|
+
* @version v4.2.8+1e68dce6
|
|
2007
|
+
*/
|
|
2005
2008
|
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
}()
|
|
2009
|
+
(function (global, factory) {
|
|
2010
|
+
module.exports = factory() ;
|
|
2011
|
+
}(commonjsGlobal, (function () {
|
|
2012
|
+
function objectOrFunction(x) {
|
|
2013
|
+
var type = typeof x;
|
|
2014
|
+
return x !== null && (type === 'object' || type === 'function');
|
|
2015
|
+
}
|
|
2009
2016
|
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
s = arguments[i];
|
|
2017
|
+
function isFunction(x) {
|
|
2018
|
+
return typeof x === 'function';
|
|
2019
|
+
}
|
|
2014
2020
|
|
|
2015
|
-
for (var p in s) {
|
|
2016
|
-
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
2021
|
|
|
2020
|
-
|
|
2022
|
+
|
|
2023
|
+
var _isArray = void 0;
|
|
2024
|
+
if (Array.isArray) {
|
|
2025
|
+
_isArray = Array.isArray;
|
|
2026
|
+
} else {
|
|
2027
|
+
_isArray = function (x) {
|
|
2028
|
+
return Object.prototype.toString.call(x) === '[object Array]';
|
|
2021
2029
|
};
|
|
2030
|
+
}
|
|
2022
2031
|
|
|
2023
|
-
|
|
2024
|
-
};
|
|
2032
|
+
var isArray = _isArray;
|
|
2025
2033
|
|
|
2026
|
-
var
|
|
2027
|
-
|
|
2034
|
+
var len = 0;
|
|
2035
|
+
var vertxNext = void 0;
|
|
2036
|
+
var customSchedulerFn = void 0;
|
|
2028
2037
|
|
|
2029
|
-
|
|
2030
|
-
|
|
2038
|
+
var asap = function asap(callback, arg) {
|
|
2039
|
+
queue[len] = callback;
|
|
2040
|
+
queue[len + 1] = arg;
|
|
2041
|
+
len += 2;
|
|
2042
|
+
if (len === 2) {
|
|
2043
|
+
// If len is 2, that means that we need to schedule an async flush.
|
|
2044
|
+
// If additional callbacks are queued before the queue is flushed, they
|
|
2045
|
+
// will be processed by this flush that we are scheduling.
|
|
2046
|
+
if (customSchedulerFn) {
|
|
2047
|
+
customSchedulerFn(flush);
|
|
2048
|
+
} else {
|
|
2049
|
+
scheduleFlush();
|
|
2050
|
+
}
|
|
2031
2051
|
}
|
|
2052
|
+
};
|
|
2032
2053
|
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
return t;
|
|
2037
|
-
}; // eslint-disable-next-line max-classes-per-file
|
|
2054
|
+
function setScheduler(scheduleFn) {
|
|
2055
|
+
customSchedulerFn = scheduleFn;
|
|
2056
|
+
}
|
|
2038
2057
|
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
function BaseValidator(value, rule, options) {
|
|
2043
|
-
this.value = value;
|
|
2058
|
+
function setAsap(asapFn) {
|
|
2059
|
+
asap = asapFn;
|
|
2060
|
+
}
|
|
2044
2061
|
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2062
|
+
var browserWindow = typeof window !== 'undefined' ? window : undefined;
|
|
2063
|
+
var browserGlobal = browserWindow || {};
|
|
2064
|
+
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
|
|
2065
|
+
var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
|
|
2048
2066
|
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2067
|
+
// test for web worker but not in IE10
|
|
2068
|
+
var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
|
|
2069
|
+
|
|
2070
|
+
// node
|
|
2071
|
+
function useNextTick() {
|
|
2072
|
+
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
|
|
2073
|
+
// see https://github.com/cujojs/when/issues/410 for details
|
|
2074
|
+
return function () {
|
|
2075
|
+
return process.nextTick(flush);
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
// vertx
|
|
2080
|
+
function useVertxTimer() {
|
|
2081
|
+
if (typeof vertxNext !== 'undefined') {
|
|
2082
|
+
return function () {
|
|
2083
|
+
vertxNext(flush);
|
|
2055
2084
|
};
|
|
2056
|
-
this.field = options.field || '';
|
|
2057
|
-
this.rule = rest;
|
|
2058
|
-
this.validateRules = [];
|
|
2059
|
-
this.curValidMsgTemplate = mergeMsgTemplate(messageTemplate, options.validateMessage);
|
|
2060
2085
|
}
|
|
2061
2086
|
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
if (isEmptyValue(this.value) || isEmptyArray(this.value)) {
|
|
2065
|
-
this.error.message = [this.message || getMsgTemplate(this.curValidMsgTemplate, 'required', [this.field])];
|
|
2066
|
-
this.error.errorTypes = ['required'];
|
|
2067
|
-
return false;
|
|
2068
|
-
}
|
|
2087
|
+
return useSetTimeout();
|
|
2088
|
+
}
|
|
2069
2089
|
|
|
2070
|
-
|
|
2090
|
+
function useMutationObserver() {
|
|
2091
|
+
var iterations = 0;
|
|
2092
|
+
var observer = new BrowserMutationObserver(flush);
|
|
2093
|
+
var node = document.createTextNode('');
|
|
2094
|
+
observer.observe(node, { characterData: true });
|
|
2095
|
+
|
|
2096
|
+
return function () {
|
|
2097
|
+
node.data = iterations = ++iterations % 2;
|
|
2071
2098
|
};
|
|
2099
|
+
}
|
|
2072
2100
|
|
|
2073
|
-
|
|
2074
|
-
|
|
2101
|
+
// web worker
|
|
2102
|
+
function useMessageChannel() {
|
|
2103
|
+
var channel = new MessageChannel();
|
|
2104
|
+
channel.port1.onmessage = flush;
|
|
2105
|
+
return function () {
|
|
2106
|
+
return channel.port2.postMessage(0);
|
|
2107
|
+
};
|
|
2108
|
+
}
|
|
2075
2109
|
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2110
|
+
function useSetTimeout() {
|
|
2111
|
+
// Store setTimeout reference so es6-promise will be unaffected by
|
|
2112
|
+
// other code modifying setTimeout (like sinon.useFakeTimers())
|
|
2113
|
+
var globalSetTimeout = setTimeout;
|
|
2114
|
+
return function () {
|
|
2115
|
+
return globalSetTimeout(flush, 1);
|
|
2080
2116
|
};
|
|
2117
|
+
}
|
|
2081
2118
|
|
|
2082
|
-
|
|
2083
|
-
|
|
2119
|
+
var queue = new Array(1000);
|
|
2120
|
+
function flush() {
|
|
2121
|
+
for (var i = 0; i < len; i += 2) {
|
|
2122
|
+
var callback = queue[i];
|
|
2123
|
+
var arg = queue[i + 1];
|
|
2084
2124
|
|
|
2085
|
-
|
|
2086
|
-
values = _a.values;
|
|
2125
|
+
callback(arg);
|
|
2087
2126
|
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
(_b = this.error.message) === null || _b === void 0 ? void 0 : _b.push(theMessage);
|
|
2092
|
-
return theMessage;
|
|
2093
|
-
}
|
|
2127
|
+
queue[i] = undefined;
|
|
2128
|
+
queue[i + 1] = undefined;
|
|
2129
|
+
}
|
|
2094
2130
|
|
|
2095
|
-
|
|
2096
|
-
|
|
2131
|
+
len = 0;
|
|
2132
|
+
}
|
|
2097
2133
|
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2134
|
+
function attemptVertx() {
|
|
2135
|
+
try {
|
|
2136
|
+
var vertx = Function('return this')().require('vertx');
|
|
2137
|
+
vertxNext = vertx.runOnLoop || vertx.runOnContext;
|
|
2138
|
+
return useVertxTimer();
|
|
2139
|
+
} catch (e) {
|
|
2140
|
+
return useSetTimeout();
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2101
2143
|
|
|
2102
|
-
|
|
2103
|
-
|
|
2144
|
+
var scheduleFlush = void 0;
|
|
2145
|
+
// Decide what async method to use to triggering processing of queued callbacks:
|
|
2146
|
+
if (isNode) {
|
|
2147
|
+
scheduleFlush = useNextTick();
|
|
2148
|
+
} else if (BrowserMutationObserver) {
|
|
2149
|
+
scheduleFlush = useMutationObserver();
|
|
2150
|
+
} else if (isWorker) {
|
|
2151
|
+
scheduleFlush = useMessageChannel();
|
|
2152
|
+
} else if (browserWindow === undefined && typeof commonjsRequire === 'function') {
|
|
2153
|
+
scheduleFlush = attemptVertx();
|
|
2154
|
+
} else {
|
|
2155
|
+
scheduleFlush = useSetTimeout();
|
|
2156
|
+
}
|
|
2104
2157
|
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
function (_super) {
|
|
2108
|
-
__extends(BooleanValidator, _super);
|
|
2158
|
+
function then(onFulfillment, onRejection) {
|
|
2159
|
+
var parent = this;
|
|
2109
2160
|
|
|
2110
|
-
|
|
2111
|
-
var _this = _super.call(this, value, rules, options) || this;
|
|
2161
|
+
var child = new this.constructor(noop);
|
|
2112
2162
|
|
|
2113
|
-
|
|
2114
|
-
|
|
2163
|
+
if (child[PROMISE_ID] === undefined) {
|
|
2164
|
+
makePromise(child);
|
|
2115
2165
|
}
|
|
2116
2166
|
|
|
2117
|
-
|
|
2118
|
-
return this.dealError(!isEmptyValue(this.value) && this.value !== str, {
|
|
2119
|
-
errTemplate: 'boolean.equal',
|
|
2120
|
-
values: [this.field, "" + str]
|
|
2121
|
-
});
|
|
2122
|
-
};
|
|
2167
|
+
var _state = parent._state;
|
|
2123
2168
|
|
|
2124
|
-
return BooleanValidator;
|
|
2125
|
-
}(BaseValidator);
|
|
2126
2169
|
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
_this.validateRules = ['min', 'max', 'equal', 'positive', 'negative'];
|
|
2136
|
-
return _this;
|
|
2170
|
+
if (_state) {
|
|
2171
|
+
var callback = arguments[_state - 1];
|
|
2172
|
+
asap(function () {
|
|
2173
|
+
return invokeCallback(_state, child, callback, parent._result);
|
|
2174
|
+
});
|
|
2175
|
+
} else {
|
|
2176
|
+
subscribe(parent, child, onFulfillment, onRejection);
|
|
2137
2177
|
}
|
|
2138
2178
|
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
errTemplate: 'number.min',
|
|
2142
|
-
values: [this.field, "" + num]
|
|
2143
|
-
});
|
|
2144
|
-
};
|
|
2179
|
+
return child;
|
|
2180
|
+
}
|
|
2145
2181
|
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
values: [this.field, "" + num]
|
|
2150
|
-
});
|
|
2151
|
-
};
|
|
2182
|
+
/**
|
|
2183
|
+
`Promise.resolve` returns a promise that will become resolved with the
|
|
2184
|
+
passed `value`. It is shorthand for the following:
|
|
2152
2185
|
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
});
|
|
2158
|
-
};
|
|
2186
|
+
```javascript
|
|
2187
|
+
let promise = new Promise(function(resolve, reject){
|
|
2188
|
+
resolve(1);
|
|
2189
|
+
});
|
|
2159
2190
|
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
});
|
|
2165
|
-
};
|
|
2191
|
+
promise.then(function(value){
|
|
2192
|
+
// value === 1
|
|
2193
|
+
});
|
|
2194
|
+
```
|
|
2166
2195
|
|
|
2167
|
-
|
|
2168
|
-
return this.dealError(!isEmptyValue(this.value) && this.value > 0, {
|
|
2169
|
-
errTemplate: 'number.negative',
|
|
2170
|
-
values: [this.field]
|
|
2171
|
-
});
|
|
2172
|
-
};
|
|
2196
|
+
Instead of writing the above, your code now simply becomes the following:
|
|
2173
2197
|
|
|
2174
|
-
|
|
2175
|
-
|
|
2198
|
+
```javascript
|
|
2199
|
+
let promise = Promise.resolve(1);
|
|
2176
2200
|
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2201
|
+
promise.then(function(value){
|
|
2202
|
+
// value === 1
|
|
2203
|
+
});
|
|
2204
|
+
```
|
|
2181
2205
|
|
|
2182
|
-
|
|
2183
|
-
|
|
2206
|
+
@method resolve
|
|
2207
|
+
@static
|
|
2208
|
+
@param {Any} value value that the returned promise will be resolved with
|
|
2209
|
+
Useful for tooling.
|
|
2210
|
+
@return {Promise} a promise that will become fulfilled with the given
|
|
2211
|
+
`value`
|
|
2212
|
+
*/
|
|
2213
|
+
function resolve$1(object) {
|
|
2214
|
+
/*jshint validthis:true */
|
|
2215
|
+
var Constructor = this;
|
|
2184
2216
|
|
|
2185
|
-
|
|
2186
|
-
return
|
|
2217
|
+
if (object && typeof object === 'object' && object.constructor === Constructor) {
|
|
2218
|
+
return object;
|
|
2187
2219
|
}
|
|
2188
2220
|
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
});
|
|
2194
|
-
};
|
|
2221
|
+
var promise = new Constructor(noop);
|
|
2222
|
+
resolve(promise, object);
|
|
2223
|
+
return promise;
|
|
2224
|
+
}
|
|
2195
2225
|
|
|
2196
|
-
|
|
2197
|
-
return this.dealError(!isEmptyValue(this.value) && this.value.length > num, {
|
|
2198
|
-
errTemplate: 'string.max',
|
|
2199
|
-
values: [this.field, "" + num]
|
|
2200
|
-
});
|
|
2201
|
-
};
|
|
2226
|
+
var PROMISE_ID = Math.random().toString(36).substring(2);
|
|
2202
2227
|
|
|
2203
|
-
|
|
2204
|
-
return this.dealError(!isEmptyValue(this.value) && this.value.length !== num, {
|
|
2205
|
-
errTemplate: 'string.len',
|
|
2206
|
-
values: [this.field, "" + num]
|
|
2207
|
-
});
|
|
2208
|
-
};
|
|
2228
|
+
function noop() {}
|
|
2209
2229
|
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
values: [this.field, "" + str]
|
|
2214
|
-
});
|
|
2215
|
-
};
|
|
2230
|
+
var PENDING = void 0;
|
|
2231
|
+
var FULFILLED = 1;
|
|
2232
|
+
var REJECTED = 2;
|
|
2216
2233
|
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
errTemplate: 'string.match',
|
|
2221
|
-
values: [this.field, regStr]
|
|
2222
|
-
});
|
|
2223
|
-
};
|
|
2234
|
+
function selfFulfillment() {
|
|
2235
|
+
return new TypeError("You cannot resolve a promise with itself");
|
|
2236
|
+
}
|
|
2224
2237
|
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
errTemplate: 'string.uppercase',
|
|
2229
|
-
values: [this.field]
|
|
2230
|
-
});
|
|
2231
|
-
};
|
|
2238
|
+
function cannotReturnOwn() {
|
|
2239
|
+
return new TypeError('A promises callback cannot return that same promise.');
|
|
2240
|
+
}
|
|
2232
2241
|
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2242
|
+
function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) {
|
|
2243
|
+
try {
|
|
2244
|
+
then$$1.call(value, fulfillmentHandler, rejectionHandler);
|
|
2245
|
+
} catch (e) {
|
|
2246
|
+
return e;
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2240
2249
|
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2250
|
+
function handleForeignThenable(promise, thenable, then$$1) {
|
|
2251
|
+
asap(function (promise) {
|
|
2252
|
+
var sealed = false;
|
|
2253
|
+
var error = tryThen(then$$1, thenable, function (value) {
|
|
2254
|
+
if (sealed) {
|
|
2255
|
+
return;
|
|
2256
|
+
}
|
|
2257
|
+
sealed = true;
|
|
2258
|
+
if (thenable !== value) {
|
|
2259
|
+
resolve(promise, value);
|
|
2260
|
+
} else {
|
|
2261
|
+
fulfill(promise, value);
|
|
2262
|
+
}
|
|
2263
|
+
}, function (reason) {
|
|
2264
|
+
if (sealed) {
|
|
2265
|
+
return;
|
|
2266
|
+
}
|
|
2267
|
+
sealed = true;
|
|
2247
2268
|
|
|
2248
|
-
|
|
2249
|
-
|
|
2269
|
+
reject(promise, reason);
|
|
2270
|
+
}, 'Settle: ' + (promise._label || ' unknown promise'));
|
|
2250
2271
|
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2272
|
+
if (!sealed && error) {
|
|
2273
|
+
sealed = true;
|
|
2274
|
+
reject(promise, error);
|
|
2275
|
+
}
|
|
2276
|
+
}, promise);
|
|
2277
|
+
}
|
|
2255
2278
|
|
|
2256
|
-
|
|
2257
|
-
|
|
2279
|
+
function handleOwnThenable(promise, thenable) {
|
|
2280
|
+
if (thenable._state === FULFILLED) {
|
|
2281
|
+
fulfill(promise, thenable._result);
|
|
2282
|
+
} else if (thenable._state === REJECTED) {
|
|
2283
|
+
reject(promise, thenable._result);
|
|
2284
|
+
} else {
|
|
2285
|
+
subscribe(thenable, undefined, function (value) {
|
|
2286
|
+
return resolve(promise, value);
|
|
2287
|
+
}, function (reason) {
|
|
2288
|
+
return reject(promise, reason);
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2258
2292
|
|
|
2259
|
-
|
|
2260
|
-
|
|
2293
|
+
function handleMaybeThenable(promise, maybeThenable, then$$1) {
|
|
2294
|
+
if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) {
|
|
2295
|
+
handleOwnThenable(promise, maybeThenable);
|
|
2296
|
+
} else {
|
|
2297
|
+
if (then$$1 === undefined) {
|
|
2298
|
+
fulfill(promise, maybeThenable);
|
|
2299
|
+
} else if (isFunction(then$$1)) {
|
|
2300
|
+
handleForeignThenable(promise, maybeThenable, then$$1);
|
|
2301
|
+
} else {
|
|
2302
|
+
fulfill(promise, maybeThenable);
|
|
2303
|
+
}
|
|
2261
2304
|
}
|
|
2305
|
+
}
|
|
2262
2306
|
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2307
|
+
function resolve(promise, value) {
|
|
2308
|
+
if (promise === value) {
|
|
2309
|
+
reject(promise, selfFulfillment());
|
|
2310
|
+
} else if (objectOrFunction(value)) {
|
|
2311
|
+
var then$$1 = void 0;
|
|
2312
|
+
try {
|
|
2313
|
+
then$$1 = value.then;
|
|
2314
|
+
} catch (error) {
|
|
2315
|
+
reject(promise, error);
|
|
2316
|
+
return;
|
|
2317
|
+
}
|
|
2318
|
+
handleMaybeThenable(promise, value, then$$1);
|
|
2319
|
+
} else {
|
|
2320
|
+
fulfill(promise, value);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2269
2323
|
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
});
|
|
2275
|
-
};
|
|
2324
|
+
function publishRejection(promise) {
|
|
2325
|
+
if (promise._onerror) {
|
|
2326
|
+
promise._onerror(promise._result);
|
|
2327
|
+
}
|
|
2276
2328
|
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
errTemplate: 'array.equal',
|
|
2280
|
-
values: [this.field, "" + JSON.stringify(sub)]
|
|
2281
|
-
});
|
|
2282
|
-
};
|
|
2283
|
-
|
|
2284
|
-
ArrayValidator.prototype.includes = function (sub) {
|
|
2285
|
-
var _this = this;
|
|
2286
|
-
|
|
2287
|
-
return this.dealError(sub.some(function (el) {
|
|
2288
|
-
return !_this.value.includes(el);
|
|
2289
|
-
}), {
|
|
2290
|
-
errTemplate: 'array.includes',
|
|
2291
|
-
values: [this.field, "" + JSON.stringify(sub)]
|
|
2292
|
-
});
|
|
2293
|
-
};
|
|
2329
|
+
publish(promise);
|
|
2330
|
+
}
|
|
2294
2331
|
|
|
2295
|
-
|
|
2296
|
-
|
|
2332
|
+
function fulfill(promise, value) {
|
|
2333
|
+
if (promise._state !== PENDING) {
|
|
2334
|
+
return;
|
|
2335
|
+
}
|
|
2297
2336
|
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
function (_super) {
|
|
2301
|
-
__extends(ObjectValidator, _super);
|
|
2337
|
+
promise._result = value;
|
|
2338
|
+
promise._state = FULFILLED;
|
|
2302
2339
|
|
|
2303
|
-
|
|
2304
|
-
|
|
2340
|
+
if (promise._subscribers.length !== 0) {
|
|
2341
|
+
asap(publish, promise);
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2305
2344
|
|
|
2306
|
-
|
|
2307
|
-
|
|
2345
|
+
function reject(promise, reason) {
|
|
2346
|
+
if (promise._state !== PENDING) {
|
|
2347
|
+
return;
|
|
2308
2348
|
}
|
|
2349
|
+
promise._state = REJECTED;
|
|
2350
|
+
promise._result = reason;
|
|
2309
2351
|
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
errTemplate: 'object.deepEqual',
|
|
2313
|
-
values: [this.field, "" + JSON.stringify(sub)]
|
|
2314
|
-
});
|
|
2315
|
-
};
|
|
2352
|
+
asap(publishRejection, promise);
|
|
2353
|
+
}
|
|
2316
2354
|
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
return !allKeys.includes(theKey);
|
|
2321
|
-
}), {
|
|
2322
|
-
errTemplate: 'object.hasKeys',
|
|
2323
|
-
values: [this.field, "" + JSON.stringify(keys)]
|
|
2324
|
-
});
|
|
2325
|
-
};
|
|
2355
|
+
function subscribe(parent, child, onFulfillment, onRejection) {
|
|
2356
|
+
var _subscribers = parent._subscribers;
|
|
2357
|
+
var length = _subscribers.length;
|
|
2326
2358
|
|
|
2327
|
-
return ObjectValidator;
|
|
2328
|
-
}(BaseValidator);
|
|
2329
2359
|
|
|
2330
|
-
|
|
2331
|
-
/** @class */
|
|
2332
|
-
function (_super) {
|
|
2333
|
-
__extends(CustomValidator, _super);
|
|
2360
|
+
parent._onerror = null;
|
|
2334
2361
|
|
|
2335
|
-
|
|
2336
|
-
|
|
2362
|
+
_subscribers[length] = child;
|
|
2363
|
+
_subscribers[length + FULFILLED] = onFulfillment;
|
|
2364
|
+
_subscribers[length + REJECTED] = onRejection;
|
|
2365
|
+
|
|
2366
|
+
if (length === 0 && parent._state) {
|
|
2367
|
+
asap(publish, parent);
|
|
2337
2368
|
}
|
|
2369
|
+
}
|
|
2338
2370
|
|
|
2339
|
-
|
|
2340
|
-
|
|
2371
|
+
function publish(promise) {
|
|
2372
|
+
var subscribers = promise._subscribers;
|
|
2373
|
+
var settled = promise._state;
|
|
2341
2374
|
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
var ret = validatorTool(_this.value, function (message) {
|
|
2346
|
-
if (message === void 0) {
|
|
2347
|
-
message = '';
|
|
2348
|
-
}
|
|
2375
|
+
if (subscribers.length === 0) {
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2349
2378
|
|
|
2350
|
-
|
|
2351
|
-
|
|
2379
|
+
var child = void 0,
|
|
2380
|
+
callback = void 0,
|
|
2381
|
+
detail = promise._result;
|
|
2352
2382
|
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
validateLevel: validateLevel
|
|
2362
|
-
}));
|
|
2363
|
-
}
|
|
2364
|
-
});
|
|
2383
|
+
for (var i = 0; i < subscribers.length; i += 3) {
|
|
2384
|
+
child = subscribers[i];
|
|
2385
|
+
callback = subscribers[i + settled];
|
|
2386
|
+
|
|
2387
|
+
if (child) {
|
|
2388
|
+
invokeCallback(settled, child, callback, detail);
|
|
2389
|
+
} else {
|
|
2390
|
+
callback(detail);
|
|
2365
2391
|
}
|
|
2392
|
+
}
|
|
2366
2393
|
|
|
2367
|
-
|
|
2368
|
-
|
|
2394
|
+
promise._subscribers.length = 0;
|
|
2395
|
+
}
|
|
2369
2396
|
|
|
2370
|
-
|
|
2371
|
-
|
|
2397
|
+
function invokeCallback(settled, promise, callback, detail) {
|
|
2398
|
+
var hasCallback = isFunction(callback),
|
|
2399
|
+
value = void 0,
|
|
2400
|
+
error = void 0,
|
|
2401
|
+
succeeded = true;
|
|
2372
2402
|
|
|
2373
|
-
|
|
2403
|
+
if (hasCallback) {
|
|
2404
|
+
try {
|
|
2405
|
+
value = callback(detail);
|
|
2406
|
+
} catch (e) {
|
|
2407
|
+
succeeded = false;
|
|
2408
|
+
error = e;
|
|
2409
|
+
}
|
|
2374
2410
|
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
}, fn(module, module.exports), module.exports;
|
|
2383
|
-
}
|
|
2411
|
+
if (promise === value) {
|
|
2412
|
+
reject(promise, cannotReturnOwn());
|
|
2413
|
+
return;
|
|
2414
|
+
}
|
|
2415
|
+
} else {
|
|
2416
|
+
value = detail;
|
|
2417
|
+
}
|
|
2384
2418
|
|
|
2385
|
-
|
|
2386
|
-
|
|
2419
|
+
if (promise._state !== PENDING) ; else if (hasCallback && succeeded) {
|
|
2420
|
+
resolve(promise, value);
|
|
2421
|
+
} else if (succeeded === false) {
|
|
2422
|
+
reject(promise, error);
|
|
2423
|
+
} else if (settled === FULFILLED) {
|
|
2424
|
+
fulfill(promise, value);
|
|
2425
|
+
} else if (settled === REJECTED) {
|
|
2426
|
+
reject(promise, value);
|
|
2427
|
+
}
|
|
2387
2428
|
}
|
|
2388
2429
|
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2430
|
+
function initializePromise(promise, resolver) {
|
|
2431
|
+
try {
|
|
2432
|
+
resolver(function resolvePromise(value) {
|
|
2433
|
+
resolve(promise, value);
|
|
2434
|
+
}, function rejectPromise(reason) {
|
|
2435
|
+
reject(promise, reason);
|
|
2436
|
+
});
|
|
2437
|
+
} catch (e) {
|
|
2438
|
+
reject(promise, e);
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2397
2441
|
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
function objectOrFunction(x) {
|
|
2402
|
-
var type = typeof x;
|
|
2403
|
-
return x !== null && (type === 'object' || type === 'function');
|
|
2442
|
+
var id = 0;
|
|
2443
|
+
function nextId() {
|
|
2444
|
+
return id++;
|
|
2404
2445
|
}
|
|
2405
2446
|
|
|
2406
|
-
function
|
|
2407
|
-
|
|
2447
|
+
function makePromise(promise) {
|
|
2448
|
+
promise[PROMISE_ID] = id++;
|
|
2449
|
+
promise._state = undefined;
|
|
2450
|
+
promise._result = undefined;
|
|
2451
|
+
promise._subscribers = [];
|
|
2408
2452
|
}
|
|
2409
2453
|
|
|
2454
|
+
function validationError() {
|
|
2455
|
+
return new Error('Array Methods must be provided an Array');
|
|
2456
|
+
}
|
|
2410
2457
|
|
|
2458
|
+
var Enumerator = function () {
|
|
2459
|
+
function Enumerator(Constructor, input) {
|
|
2460
|
+
this._instanceConstructor = Constructor;
|
|
2461
|
+
this.promise = new Constructor(noop);
|
|
2411
2462
|
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
} else {
|
|
2416
|
-
_isArray = function (x) {
|
|
2417
|
-
return Object.prototype.toString.call(x) === '[object Array]';
|
|
2418
|
-
};
|
|
2419
|
-
}
|
|
2463
|
+
if (!this.promise[PROMISE_ID]) {
|
|
2464
|
+
makePromise(this.promise);
|
|
2465
|
+
}
|
|
2420
2466
|
|
|
2421
|
-
|
|
2467
|
+
if (isArray(input)) {
|
|
2468
|
+
this.length = input.length;
|
|
2469
|
+
this._remaining = input.length;
|
|
2422
2470
|
|
|
2423
|
-
|
|
2424
|
-
var vertxNext = void 0;
|
|
2425
|
-
var customSchedulerFn = void 0;
|
|
2471
|
+
this._result = new Array(this.length);
|
|
2426
2472
|
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
customSchedulerFn(flush);
|
|
2473
|
+
if (this.length === 0) {
|
|
2474
|
+
fulfill(this.promise, this._result);
|
|
2475
|
+
} else {
|
|
2476
|
+
this.length = this.length || 0;
|
|
2477
|
+
this._enumerate(input);
|
|
2478
|
+
if (this._remaining === 0) {
|
|
2479
|
+
fulfill(this.promise, this._result);
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2437
2482
|
} else {
|
|
2438
|
-
|
|
2483
|
+
reject(this.promise, validationError());
|
|
2439
2484
|
}
|
|
2440
2485
|
}
|
|
2441
|
-
};
|
|
2442
2486
|
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2487
|
+
Enumerator.prototype._enumerate = function _enumerate(input) {
|
|
2488
|
+
for (var i = 0; this._state === PENDING && i < input.length; i++) {
|
|
2489
|
+
this._eachEntry(input[i], i);
|
|
2490
|
+
}
|
|
2491
|
+
};
|
|
2446
2492
|
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2493
|
+
Enumerator.prototype._eachEntry = function _eachEntry(entry, i) {
|
|
2494
|
+
var c = this._instanceConstructor;
|
|
2495
|
+
var resolve$$1 = c.resolve;
|
|
2450
2496
|
|
|
2451
|
-
var browserWindow = typeof window !== 'undefined' ? window : undefined;
|
|
2452
|
-
var browserGlobal = browserWindow || {};
|
|
2453
|
-
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
|
|
2454
|
-
var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
|
|
2455
2497
|
|
|
2456
|
-
|
|
2457
|
-
|
|
2498
|
+
if (resolve$$1 === resolve$1) {
|
|
2499
|
+
var _then = void 0;
|
|
2500
|
+
var error = void 0;
|
|
2501
|
+
var didError = false;
|
|
2502
|
+
try {
|
|
2503
|
+
_then = entry.then;
|
|
2504
|
+
} catch (e) {
|
|
2505
|
+
didError = true;
|
|
2506
|
+
error = e;
|
|
2507
|
+
}
|
|
2458
2508
|
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2509
|
+
if (_then === then && entry._state !== PENDING) {
|
|
2510
|
+
this._settledAt(entry._state, i, entry._result);
|
|
2511
|
+
} else if (typeof _then !== 'function') {
|
|
2512
|
+
this._remaining--;
|
|
2513
|
+
this._result[i] = entry;
|
|
2514
|
+
} else if (c === Promise$1) {
|
|
2515
|
+
var promise = new c(noop);
|
|
2516
|
+
if (didError) {
|
|
2517
|
+
reject(promise, error);
|
|
2518
|
+
} else {
|
|
2519
|
+
handleMaybeThenable(promise, entry, _then);
|
|
2520
|
+
}
|
|
2521
|
+
this._willSettleAt(promise, i);
|
|
2522
|
+
} else {
|
|
2523
|
+
this._willSettleAt(new c(function (resolve$$1) {
|
|
2524
|
+
return resolve$$1(entry);
|
|
2525
|
+
}), i);
|
|
2526
|
+
}
|
|
2527
|
+
} else {
|
|
2528
|
+
this._willSettleAt(resolve$$1(entry), i);
|
|
2529
|
+
}
|
|
2465
2530
|
};
|
|
2466
|
-
}
|
|
2467
|
-
|
|
2468
|
-
// vertx
|
|
2469
|
-
function useVertxTimer() {
|
|
2470
|
-
if (typeof vertxNext !== 'undefined') {
|
|
2471
|
-
return function () {
|
|
2472
|
-
vertxNext(flush);
|
|
2473
|
-
};
|
|
2474
|
-
}
|
|
2475
2531
|
|
|
2476
|
-
|
|
2477
|
-
|
|
2532
|
+
Enumerator.prototype._settledAt = function _settledAt(state, i, value) {
|
|
2533
|
+
var promise = this.promise;
|
|
2478
2534
|
|
|
2479
|
-
function useMutationObserver() {
|
|
2480
|
-
var iterations = 0;
|
|
2481
|
-
var observer = new BrowserMutationObserver(flush);
|
|
2482
|
-
var node = document.createTextNode('');
|
|
2483
|
-
observer.observe(node, { characterData: true });
|
|
2484
2535
|
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
};
|
|
2488
|
-
}
|
|
2536
|
+
if (promise._state === PENDING) {
|
|
2537
|
+
this._remaining--;
|
|
2489
2538
|
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
};
|
|
2497
|
-
}
|
|
2539
|
+
if (state === REJECTED) {
|
|
2540
|
+
reject(promise, value);
|
|
2541
|
+
} else {
|
|
2542
|
+
this._result[i] = value;
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2498
2545
|
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
var globalSetTimeout = setTimeout;
|
|
2503
|
-
return function () {
|
|
2504
|
-
return globalSetTimeout(flush, 1);
|
|
2546
|
+
if (this._remaining === 0) {
|
|
2547
|
+
fulfill(promise, this._result);
|
|
2548
|
+
}
|
|
2505
2549
|
};
|
|
2506
|
-
}
|
|
2507
2550
|
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
for (var i = 0; i < len; i += 2) {
|
|
2511
|
-
var callback = queue[i];
|
|
2512
|
-
var arg = queue[i + 1];
|
|
2513
|
-
|
|
2514
|
-
callback(arg);
|
|
2551
|
+
Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) {
|
|
2552
|
+
var enumerator = this;
|
|
2515
2553
|
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2554
|
+
subscribe(promise, undefined, function (value) {
|
|
2555
|
+
return enumerator._settledAt(FULFILLED, i, value);
|
|
2556
|
+
}, function (reason) {
|
|
2557
|
+
return enumerator._settledAt(REJECTED, i, reason);
|
|
2558
|
+
});
|
|
2559
|
+
};
|
|
2519
2560
|
|
|
2520
|
-
|
|
2521
|
-
}
|
|
2561
|
+
return Enumerator;
|
|
2562
|
+
}();
|
|
2522
2563
|
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
} catch (e) {
|
|
2529
|
-
return useSetTimeout();
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2564
|
+
/**
|
|
2565
|
+
`Promise.all` accepts an array of promises, and returns a new promise which
|
|
2566
|
+
is fulfilled with an array of fulfillment values for the passed promises, or
|
|
2567
|
+
rejected with the reason of the first passed promise to be rejected. It casts all
|
|
2568
|
+
elements of the passed iterable to promises as it runs this algorithm.
|
|
2532
2569
|
|
|
2533
|
-
|
|
2534
|
-
// Decide what async method to use to triggering processing of queued callbacks:
|
|
2535
|
-
if (isNode) {
|
|
2536
|
-
scheduleFlush = useNextTick();
|
|
2537
|
-
} else if (BrowserMutationObserver) {
|
|
2538
|
-
scheduleFlush = useMutationObserver();
|
|
2539
|
-
} else if (isWorker) {
|
|
2540
|
-
scheduleFlush = useMessageChannel();
|
|
2541
|
-
} else if (browserWindow === undefined && typeof commonjsRequire === 'function') {
|
|
2542
|
-
scheduleFlush = attemptVertx();
|
|
2543
|
-
} else {
|
|
2544
|
-
scheduleFlush = useSetTimeout();
|
|
2545
|
-
}
|
|
2570
|
+
Example:
|
|
2546
2571
|
|
|
2547
|
-
|
|
2548
|
-
|
|
2572
|
+
```javascript
|
|
2573
|
+
let promise1 = resolve(1);
|
|
2574
|
+
let promise2 = resolve(2);
|
|
2575
|
+
let promise3 = resolve(3);
|
|
2576
|
+
let promises = [ promise1, promise2, promise3 ];
|
|
2549
2577
|
|
|
2550
|
-
|
|
2578
|
+
Promise.all(promises).then(function(array){
|
|
2579
|
+
// The array here would be [ 1, 2, 3 ];
|
|
2580
|
+
});
|
|
2581
|
+
```
|
|
2551
2582
|
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2583
|
+
If any of the `promises` given to `all` are rejected, the first promise
|
|
2584
|
+
that is rejected will be given as an argument to the returned promises's
|
|
2585
|
+
rejection handler. For example:
|
|
2555
2586
|
|
|
2556
|
-
|
|
2587
|
+
Example:
|
|
2557
2588
|
|
|
2589
|
+
```javascript
|
|
2590
|
+
let promise1 = resolve(1);
|
|
2591
|
+
let promise2 = reject(new Error("2"));
|
|
2592
|
+
let promise3 = reject(new Error("3"));
|
|
2593
|
+
let promises = [ promise1, promise2, promise3 ];
|
|
2558
2594
|
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
subscribe(parent, child, onFulfillment, onRejection);
|
|
2566
|
-
}
|
|
2595
|
+
Promise.all(promises).then(function(array){
|
|
2596
|
+
// Code here never runs because there are rejected promises!
|
|
2597
|
+
}, function(error) {
|
|
2598
|
+
// error.message === "2"
|
|
2599
|
+
});
|
|
2600
|
+
```
|
|
2567
2601
|
|
|
2568
|
-
|
|
2602
|
+
@method all
|
|
2603
|
+
@static
|
|
2604
|
+
@param {Array} entries array of promises
|
|
2605
|
+
@param {String} label optional string for labeling the promise.
|
|
2606
|
+
Useful for tooling.
|
|
2607
|
+
@return {Promise} promise that is fulfilled when all `promises` have been
|
|
2608
|
+
fulfilled, or rejected if any of them become rejected.
|
|
2609
|
+
@static
|
|
2610
|
+
*/
|
|
2611
|
+
function all(entries) {
|
|
2612
|
+
return new Enumerator(this, entries).promise;
|
|
2569
2613
|
}
|
|
2570
2614
|
|
|
2571
2615
|
/**
|
|
2572
|
-
`Promise.
|
|
2573
|
-
passed
|
|
2616
|
+
`Promise.race` returns a new promise which is settled in the same way as the
|
|
2617
|
+
first passed promise to settle.
|
|
2618
|
+
|
|
2619
|
+
Example:
|
|
2574
2620
|
|
|
2575
2621
|
```javascript
|
|
2576
|
-
let
|
|
2577
|
-
|
|
2622
|
+
let promise1 = new Promise(function(resolve, reject){
|
|
2623
|
+
setTimeout(function(){
|
|
2624
|
+
resolve('promise 1');
|
|
2625
|
+
}, 200);
|
|
2578
2626
|
});
|
|
2579
2627
|
|
|
2580
|
-
|
|
2581
|
-
|
|
2628
|
+
let promise2 = new Promise(function(resolve, reject){
|
|
2629
|
+
setTimeout(function(){
|
|
2630
|
+
resolve('promise 2');
|
|
2631
|
+
}, 100);
|
|
2632
|
+
});
|
|
2633
|
+
|
|
2634
|
+
Promise.race([promise1, promise2]).then(function(result){
|
|
2635
|
+
// result === 'promise 2' because it was resolved before promise1
|
|
2636
|
+
// was resolved.
|
|
2582
2637
|
});
|
|
2583
2638
|
```
|
|
2584
2639
|
|
|
2585
|
-
|
|
2640
|
+
`Promise.race` is deterministic in that only the state of the first
|
|
2641
|
+
settled promise matters. For example, even if other promises given to the
|
|
2642
|
+
`promises` array argument are resolved, but the first settled promise has
|
|
2643
|
+
become rejected before the other promises became fulfilled, the returned
|
|
2644
|
+
promise will become rejected:
|
|
2586
2645
|
|
|
2587
2646
|
```javascript
|
|
2588
|
-
let
|
|
2647
|
+
let promise1 = new Promise(function(resolve, reject){
|
|
2648
|
+
setTimeout(function(){
|
|
2649
|
+
resolve('promise 1');
|
|
2650
|
+
}, 200);
|
|
2651
|
+
});
|
|
2589
2652
|
|
|
2590
|
-
|
|
2591
|
-
|
|
2653
|
+
let promise2 = new Promise(function(resolve, reject){
|
|
2654
|
+
setTimeout(function(){
|
|
2655
|
+
reject(new Error('promise 2'));
|
|
2656
|
+
}, 100);
|
|
2657
|
+
});
|
|
2658
|
+
|
|
2659
|
+
Promise.race([promise1, promise2]).then(function(result){
|
|
2660
|
+
// Code here never runs
|
|
2661
|
+
}, function(reason){
|
|
2662
|
+
// reason.message === 'promise 2' because promise 2 became rejected before
|
|
2663
|
+
// promise 1 became fulfilled
|
|
2592
2664
|
});
|
|
2593
2665
|
```
|
|
2594
2666
|
|
|
2595
|
-
|
|
2667
|
+
An example real-world use case is implementing timeouts:
|
|
2668
|
+
|
|
2669
|
+
```javascript
|
|
2670
|
+
Promise.race([ajax('foo.json'), timeout(5000)])
|
|
2671
|
+
```
|
|
2672
|
+
|
|
2673
|
+
@method race
|
|
2596
2674
|
@static
|
|
2597
|
-
@param {
|
|
2675
|
+
@param {Array} promises array of promises to observe
|
|
2598
2676
|
Useful for tooling.
|
|
2599
|
-
@return {Promise} a promise
|
|
2600
|
-
|
|
2677
|
+
@return {Promise} a promise which settles in the same way as the first passed
|
|
2678
|
+
promise to settle.
|
|
2601
2679
|
*/
|
|
2602
|
-
function
|
|
2680
|
+
function race(entries) {
|
|
2603
2681
|
/*jshint validthis:true */
|
|
2604
2682
|
var Constructor = this;
|
|
2605
2683
|
|
|
2606
|
-
if (
|
|
2607
|
-
return
|
|
2684
|
+
if (!isArray(entries)) {
|
|
2685
|
+
return new Constructor(function (_, reject) {
|
|
2686
|
+
return reject(new TypeError('You must pass an array to race.'));
|
|
2687
|
+
});
|
|
2688
|
+
} else {
|
|
2689
|
+
return new Constructor(function (resolve, reject) {
|
|
2690
|
+
var length = entries.length;
|
|
2691
|
+
for (var i = 0; i < length; i++) {
|
|
2692
|
+
Constructor.resolve(entries[i]).then(resolve, reject);
|
|
2693
|
+
}
|
|
2694
|
+
});
|
|
2608
2695
|
}
|
|
2609
|
-
|
|
2610
|
-
var promise = new Constructor(noop);
|
|
2611
|
-
resolve(promise, object);
|
|
2612
|
-
return promise;
|
|
2613
2696
|
}
|
|
2614
2697
|
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
var PENDING = void 0;
|
|
2620
|
-
var FULFILLED = 1;
|
|
2621
|
-
var REJECTED = 2;
|
|
2698
|
+
/**
|
|
2699
|
+
`Promise.reject` returns a promise rejected with the passed `reason`.
|
|
2700
|
+
It is shorthand for the following:
|
|
2622
2701
|
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2702
|
+
```javascript
|
|
2703
|
+
let promise = new Promise(function(resolve, reject){
|
|
2704
|
+
reject(new Error('WHOOPS'));
|
|
2705
|
+
});
|
|
2626
2706
|
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2707
|
+
promise.then(function(value){
|
|
2708
|
+
// Code here doesn't run because the promise is rejected!
|
|
2709
|
+
}, function(reason){
|
|
2710
|
+
// reason.message === 'WHOOPS'
|
|
2711
|
+
});
|
|
2712
|
+
```
|
|
2630
2713
|
|
|
2631
|
-
|
|
2632
|
-
try {
|
|
2633
|
-
then$$1.call(value, fulfillmentHandler, rejectionHandler);
|
|
2634
|
-
} catch (e) {
|
|
2635
|
-
return e;
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2714
|
+
Instead of writing the above, your code now simply becomes the following:
|
|
2638
2715
|
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
var sealed = false;
|
|
2642
|
-
var error = tryThen(then$$1, thenable, function (value) {
|
|
2643
|
-
if (sealed) {
|
|
2644
|
-
return;
|
|
2645
|
-
}
|
|
2646
|
-
sealed = true;
|
|
2647
|
-
if (thenable !== value) {
|
|
2648
|
-
resolve(promise, value);
|
|
2649
|
-
} else {
|
|
2650
|
-
fulfill(promise, value);
|
|
2651
|
-
}
|
|
2652
|
-
}, function (reason) {
|
|
2653
|
-
if (sealed) {
|
|
2654
|
-
return;
|
|
2655
|
-
}
|
|
2656
|
-
sealed = true;
|
|
2716
|
+
```javascript
|
|
2717
|
+
let promise = Promise.reject(new Error('WHOOPS'));
|
|
2657
2718
|
|
|
2658
|
-
|
|
2659
|
-
|
|
2719
|
+
promise.then(function(value){
|
|
2720
|
+
// Code here doesn't run because the promise is rejected!
|
|
2721
|
+
}, function(reason){
|
|
2722
|
+
// reason.message === 'WHOOPS'
|
|
2723
|
+
});
|
|
2724
|
+
```
|
|
2660
2725
|
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
}
|
|
2726
|
+
@method reject
|
|
2727
|
+
@static
|
|
2728
|
+
@param {Any} reason value that the returned promise will be rejected with.
|
|
2729
|
+
Useful for tooling.
|
|
2730
|
+
@return {Promise} a promise rejected with the given `reason`.
|
|
2731
|
+
*/
|
|
2732
|
+
function reject$1(reason) {
|
|
2733
|
+
/*jshint validthis:true */
|
|
2734
|
+
var Constructor = this;
|
|
2735
|
+
var promise = new Constructor(noop);
|
|
2736
|
+
reject(promise, reason);
|
|
2737
|
+
return promise;
|
|
2666
2738
|
}
|
|
2667
2739
|
|
|
2668
|
-
function
|
|
2669
|
-
|
|
2670
|
-
fulfill(promise, thenable._result);
|
|
2671
|
-
} else if (thenable._state === REJECTED) {
|
|
2672
|
-
reject(promise, thenable._result);
|
|
2673
|
-
} else {
|
|
2674
|
-
subscribe(thenable, undefined, function (value) {
|
|
2675
|
-
return resolve(promise, value);
|
|
2676
|
-
}, function (reason) {
|
|
2677
|
-
return reject(promise, reason);
|
|
2678
|
-
});
|
|
2679
|
-
}
|
|
2740
|
+
function needsResolver() {
|
|
2741
|
+
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
|
|
2680
2742
|
}
|
|
2681
2743
|
|
|
2682
|
-
function
|
|
2683
|
-
|
|
2684
|
-
handleOwnThenable(promise, maybeThenable);
|
|
2685
|
-
} else {
|
|
2686
|
-
if (then$$1 === undefined) {
|
|
2687
|
-
fulfill(promise, maybeThenable);
|
|
2688
|
-
} else if (isFunction(then$$1)) {
|
|
2689
|
-
handleForeignThenable(promise, maybeThenable, then$$1);
|
|
2690
|
-
} else {
|
|
2691
|
-
fulfill(promise, maybeThenable);
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2744
|
+
function needsNew() {
|
|
2745
|
+
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
|
2694
2746
|
}
|
|
2695
2747
|
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
try {
|
|
2702
|
-
then$$1 = value.then;
|
|
2703
|
-
} catch (error) {
|
|
2704
|
-
reject(promise, error);
|
|
2705
|
-
return;
|
|
2706
|
-
}
|
|
2707
|
-
handleMaybeThenable(promise, value, then$$1);
|
|
2708
|
-
} else {
|
|
2709
|
-
fulfill(promise, value);
|
|
2710
|
-
}
|
|
2711
|
-
}
|
|
2748
|
+
/**
|
|
2749
|
+
Promise objects represent the eventual result of an asynchronous operation. The
|
|
2750
|
+
primary way of interacting with a promise is through its `then` method, which
|
|
2751
|
+
registers callbacks to receive either a promise's eventual value or the reason
|
|
2752
|
+
why the promise cannot be fulfilled.
|
|
2712
2753
|
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
promise._onerror(promise._result);
|
|
2716
|
-
}
|
|
2754
|
+
Terminology
|
|
2755
|
+
-----------
|
|
2717
2756
|
|
|
2718
|
-
|
|
2719
|
-
|
|
2757
|
+
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
|
|
2758
|
+
- `thenable` is an object or function that defines a `then` method.
|
|
2759
|
+
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
|
|
2760
|
+
- `exception` is a value that is thrown using the throw statement.
|
|
2761
|
+
- `reason` is a value that indicates why a promise was rejected.
|
|
2762
|
+
- `settled` the final resting state of a promise, fulfilled or rejected.
|
|
2720
2763
|
|
|
2721
|
-
|
|
2722
|
-
if (promise._state !== PENDING) {
|
|
2723
|
-
return;
|
|
2724
|
-
}
|
|
2764
|
+
A promise can be in one of three states: pending, fulfilled, or rejected.
|
|
2725
2765
|
|
|
2726
|
-
|
|
2727
|
-
|
|
2766
|
+
Promises that are fulfilled have a fulfillment value and are in the fulfilled
|
|
2767
|
+
state. Promises that are rejected have a rejection reason and are in the
|
|
2768
|
+
rejected state. A fulfillment value is never a thenable.
|
|
2728
2769
|
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2770
|
+
Promises can also be said to *resolve* a value. If this value is also a
|
|
2771
|
+
promise, then the original promise's settled state will match the value's
|
|
2772
|
+
settled state. So a promise that *resolves* a promise that rejects will
|
|
2773
|
+
itself reject, and a promise that *resolves* a promise that fulfills will
|
|
2774
|
+
itself fulfill.
|
|
2733
2775
|
|
|
2734
|
-
function reject(promise, reason) {
|
|
2735
|
-
if (promise._state !== PENDING) {
|
|
2736
|
-
return;
|
|
2737
|
-
}
|
|
2738
|
-
promise._state = REJECTED;
|
|
2739
|
-
promise._result = reason;
|
|
2740
2776
|
|
|
2741
|
-
|
|
2742
|
-
|
|
2777
|
+
Basic Usage:
|
|
2778
|
+
------------
|
|
2743
2779
|
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2780
|
+
```js
|
|
2781
|
+
let promise = new Promise(function(resolve, reject) {
|
|
2782
|
+
// on success
|
|
2783
|
+
resolve(value);
|
|
2747
2784
|
|
|
2785
|
+
// on failure
|
|
2786
|
+
reject(reason);
|
|
2787
|
+
});
|
|
2748
2788
|
|
|
2749
|
-
|
|
2789
|
+
promise.then(function(value) {
|
|
2790
|
+
// on fulfillment
|
|
2791
|
+
}, function(reason) {
|
|
2792
|
+
// on rejection
|
|
2793
|
+
});
|
|
2794
|
+
```
|
|
2750
2795
|
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
_subscribers[length + REJECTED] = onRejection;
|
|
2796
|
+
Advanced Usage:
|
|
2797
|
+
---------------
|
|
2754
2798
|
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
}
|
|
2758
|
-
}
|
|
2799
|
+
Promises shine when abstracting away asynchronous interactions such as
|
|
2800
|
+
`XMLHttpRequest`s.
|
|
2759
2801
|
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2802
|
+
```js
|
|
2803
|
+
function getJSON(url) {
|
|
2804
|
+
return new Promise(function(resolve, reject){
|
|
2805
|
+
let xhr = new XMLHttpRequest();
|
|
2763
2806
|
|
|
2764
|
-
|
|
2765
|
-
|
|
2807
|
+
xhr.open('GET', url);
|
|
2808
|
+
xhr.onreadystatechange = handler;
|
|
2809
|
+
xhr.responseType = 'json';
|
|
2810
|
+
xhr.setRequestHeader('Accept', 'application/json');
|
|
2811
|
+
xhr.send();
|
|
2812
|
+
|
|
2813
|
+
function handler() {
|
|
2814
|
+
if (this.readyState === this.DONE) {
|
|
2815
|
+
if (this.status === 200) {
|
|
2816
|
+
resolve(this.response);
|
|
2817
|
+
} else {
|
|
2818
|
+
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
};
|
|
2822
|
+
});
|
|
2766
2823
|
}
|
|
2767
2824
|
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2825
|
+
getJSON('/posts.json').then(function(json) {
|
|
2826
|
+
// on fulfillment
|
|
2827
|
+
}, function(reason) {
|
|
2828
|
+
// on rejection
|
|
2829
|
+
});
|
|
2830
|
+
```
|
|
2771
2831
|
|
|
2772
|
-
|
|
2773
|
-
child = subscribers[i];
|
|
2774
|
-
callback = subscribers[i + settled];
|
|
2832
|
+
Unlike callbacks, promises are great composable primitives.
|
|
2775
2833
|
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2834
|
+
```js
|
|
2835
|
+
Promise.all([
|
|
2836
|
+
getJSON('/posts'),
|
|
2837
|
+
getJSON('/comments')
|
|
2838
|
+
]).then(function(values){
|
|
2839
|
+
values[0] // => postsJSON
|
|
2840
|
+
values[1] // => commentsJSON
|
|
2782
2841
|
|
|
2783
|
-
|
|
2784
|
-
|
|
2842
|
+
return values;
|
|
2843
|
+
});
|
|
2844
|
+
```
|
|
2785
2845
|
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2846
|
+
@class Promise
|
|
2847
|
+
@param {Function} resolver
|
|
2848
|
+
Useful for tooling.
|
|
2849
|
+
@constructor
|
|
2850
|
+
*/
|
|
2791
2851
|
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
error = e;
|
|
2798
|
-
}
|
|
2852
|
+
var Promise$1 = function () {
|
|
2853
|
+
function Promise(resolver) {
|
|
2854
|
+
this[PROMISE_ID] = nextId();
|
|
2855
|
+
this._result = this._state = undefined;
|
|
2856
|
+
this._subscribers = [];
|
|
2799
2857
|
|
|
2800
|
-
if (
|
|
2801
|
-
|
|
2802
|
-
|
|
2858
|
+
if (noop !== resolver) {
|
|
2859
|
+
typeof resolver !== 'function' && needsResolver();
|
|
2860
|
+
this instanceof Promise ? initializePromise(this, resolver) : needsNew();
|
|
2803
2861
|
}
|
|
2804
|
-
} else {
|
|
2805
|
-
value = detail;
|
|
2806
2862
|
}
|
|
2807
2863
|
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2864
|
+
/**
|
|
2865
|
+
The primary way of interacting with a promise is through its `then` method,
|
|
2866
|
+
which registers callbacks to receive either a promise's eventual value or the
|
|
2867
|
+
reason why the promise cannot be fulfilled.
|
|
2868
|
+
```js
|
|
2869
|
+
findUser().then(function(user){
|
|
2870
|
+
// user is available
|
|
2871
|
+
}, function(reason){
|
|
2872
|
+
// user is unavailable, and you are given the reason why
|
|
2873
|
+
});
|
|
2874
|
+
```
|
|
2875
|
+
Chaining
|
|
2876
|
+
--------
|
|
2877
|
+
The return value of `then` is itself a promise. This second, 'downstream'
|
|
2878
|
+
promise is resolved with the return value of the first promise's fulfillment
|
|
2879
|
+
or rejection handler, or rejected if the handler throws an exception.
|
|
2880
|
+
```js
|
|
2881
|
+
findUser().then(function (user) {
|
|
2882
|
+
return user.name;
|
|
2883
|
+
}, function (reason) {
|
|
2884
|
+
return 'default name';
|
|
2885
|
+
}).then(function (userName) {
|
|
2886
|
+
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
|
2887
|
+
// will be `'default name'`
|
|
2888
|
+
});
|
|
2889
|
+
findUser().then(function (user) {
|
|
2890
|
+
throw new Error('Found user, but still unhappy');
|
|
2891
|
+
}, function (reason) {
|
|
2892
|
+
throw new Error('`findUser` rejected and we're unhappy');
|
|
2893
|
+
}).then(function (value) {
|
|
2894
|
+
// never reached
|
|
2895
|
+
}, function (reason) {
|
|
2896
|
+
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
|
2897
|
+
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
|
|
2898
|
+
});
|
|
2899
|
+
```
|
|
2900
|
+
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
|
2901
|
+
```js
|
|
2902
|
+
findUser().then(function (user) {
|
|
2903
|
+
throw new PedagogicalException('Upstream error');
|
|
2904
|
+
}).then(function (value) {
|
|
2905
|
+
// never reached
|
|
2906
|
+
}).then(function (value) {
|
|
2907
|
+
// never reached
|
|
2908
|
+
}, function (reason) {
|
|
2909
|
+
// The `PedgagocialException` is propagated all the way down to here
|
|
2910
|
+
});
|
|
2911
|
+
```
|
|
2912
|
+
Assimilation
|
|
2913
|
+
------------
|
|
2914
|
+
Sometimes the value you want to propagate to a downstream promise can only be
|
|
2915
|
+
retrieved asynchronously. This can be achieved by returning a promise in the
|
|
2916
|
+
fulfillment or rejection handler. The downstream promise will then be pending
|
|
2917
|
+
until the returned promise is settled. This is called *assimilation*.
|
|
2918
|
+
```js
|
|
2919
|
+
findUser().then(function (user) {
|
|
2920
|
+
return findCommentsByAuthor(user);
|
|
2921
|
+
}).then(function (comments) {
|
|
2922
|
+
// The user's comments are now available
|
|
2923
|
+
});
|
|
2924
|
+
```
|
|
2925
|
+
If the assimliated promise rejects, then the downstream promise will also reject.
|
|
2926
|
+
```js
|
|
2927
|
+
findUser().then(function (user) {
|
|
2928
|
+
return findCommentsByAuthor(user);
|
|
2929
|
+
}).then(function (comments) {
|
|
2930
|
+
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
|
2931
|
+
}, function (reason) {
|
|
2932
|
+
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
|
2933
|
+
});
|
|
2934
|
+
```
|
|
2935
|
+
Simple Example
|
|
2936
|
+
--------------
|
|
2937
|
+
Synchronous Example
|
|
2938
|
+
```javascript
|
|
2939
|
+
let result;
|
|
2940
|
+
try {
|
|
2941
|
+
result = findResult();
|
|
2942
|
+
// success
|
|
2943
|
+
} catch(reason) {
|
|
2944
|
+
// failure
|
|
2816
2945
|
}
|
|
2817
|
-
|
|
2946
|
+
```
|
|
2947
|
+
Errback Example
|
|
2948
|
+
```js
|
|
2949
|
+
findResult(function(result, err){
|
|
2950
|
+
if (err) {
|
|
2951
|
+
// failure
|
|
2952
|
+
} else {
|
|
2953
|
+
// success
|
|
2954
|
+
}
|
|
2955
|
+
});
|
|
2956
|
+
```
|
|
2957
|
+
Promise Example;
|
|
2958
|
+
```javascript
|
|
2959
|
+
findResult().then(function(result){
|
|
2960
|
+
// success
|
|
2961
|
+
}, function(reason){
|
|
2962
|
+
// failure
|
|
2963
|
+
});
|
|
2964
|
+
```
|
|
2965
|
+
Advanced Example
|
|
2966
|
+
--------------
|
|
2967
|
+
Synchronous Example
|
|
2968
|
+
```javascript
|
|
2969
|
+
let author, books;
|
|
2970
|
+
try {
|
|
2971
|
+
author = findAuthor();
|
|
2972
|
+
books = findBooksByAuthor(author);
|
|
2973
|
+
// success
|
|
2974
|
+
} catch(reason) {
|
|
2975
|
+
// failure
|
|
2976
|
+
}
|
|
2977
|
+
```
|
|
2978
|
+
Errback Example
|
|
2979
|
+
```js
|
|
2980
|
+
function foundBooks(books) {
|
|
2981
|
+
}
|
|
2982
|
+
function failure(reason) {
|
|
2983
|
+
}
|
|
2984
|
+
findAuthor(function(author, err){
|
|
2985
|
+
if (err) {
|
|
2986
|
+
failure(err);
|
|
2987
|
+
// failure
|
|
2988
|
+
} else {
|
|
2989
|
+
try {
|
|
2990
|
+
findBoooksByAuthor(author, function(books, err) {
|
|
2991
|
+
if (err) {
|
|
2992
|
+
failure(err);
|
|
2993
|
+
} else {
|
|
2994
|
+
try {
|
|
2995
|
+
foundBooks(books);
|
|
2996
|
+
} catch(reason) {
|
|
2997
|
+
failure(reason);
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
});
|
|
3001
|
+
} catch(error) {
|
|
3002
|
+
failure(err);
|
|
3003
|
+
}
|
|
3004
|
+
// success
|
|
3005
|
+
}
|
|
3006
|
+
});
|
|
3007
|
+
```
|
|
3008
|
+
Promise Example;
|
|
3009
|
+
```javascript
|
|
3010
|
+
findAuthor().
|
|
3011
|
+
then(findBooksByAuthor).
|
|
3012
|
+
then(function(books){
|
|
3013
|
+
// found books
|
|
3014
|
+
}).catch(function(reason){
|
|
3015
|
+
// something went wrong
|
|
3016
|
+
});
|
|
3017
|
+
```
|
|
3018
|
+
@method then
|
|
3019
|
+
@param {Function} onFulfilled
|
|
3020
|
+
@param {Function} onRejected
|
|
3021
|
+
Useful for tooling.
|
|
3022
|
+
@return {Promise}
|
|
3023
|
+
*/
|
|
2818
3024
|
|
|
2819
|
-
|
|
3025
|
+
/**
|
|
3026
|
+
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
|
|
3027
|
+
as the catch block of a try/catch statement.
|
|
3028
|
+
```js
|
|
3029
|
+
function findAuthor(){
|
|
3030
|
+
throw new Error('couldn't find that author');
|
|
3031
|
+
}
|
|
3032
|
+
// synchronous
|
|
2820
3033
|
try {
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
reject(promise, reason);
|
|
2825
|
-
});
|
|
2826
|
-
} catch (e) {
|
|
2827
|
-
reject(promise, e);
|
|
3034
|
+
findAuthor();
|
|
3035
|
+
} catch(reason) {
|
|
3036
|
+
// something went wrong
|
|
2828
3037
|
}
|
|
2829
|
-
|
|
3038
|
+
// async with promises
|
|
3039
|
+
findAuthor().catch(function(reason){
|
|
3040
|
+
// something went wrong
|
|
3041
|
+
});
|
|
3042
|
+
```
|
|
3043
|
+
@method catch
|
|
3044
|
+
@param {Function} onRejection
|
|
3045
|
+
Useful for tooling.
|
|
3046
|
+
@return {Promise}
|
|
3047
|
+
*/
|
|
2830
3048
|
|
|
2831
|
-
var id = 0;
|
|
2832
|
-
function nextId() {
|
|
2833
|
-
return id++;
|
|
2834
|
-
}
|
|
2835
3049
|
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
promise._result = undefined;
|
|
2840
|
-
promise._subscribers = [];
|
|
2841
|
-
}
|
|
3050
|
+
Promise.prototype.catch = function _catch(onRejection) {
|
|
3051
|
+
return this.then(null, onRejection);
|
|
3052
|
+
};
|
|
2842
3053
|
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
3054
|
+
/**
|
|
3055
|
+
`finally` will be invoked regardless of the promise's fate just as native
|
|
3056
|
+
try/catch/finally behaves
|
|
3057
|
+
|
|
3058
|
+
Synchronous example:
|
|
3059
|
+
|
|
3060
|
+
```js
|
|
3061
|
+
findAuthor() {
|
|
3062
|
+
if (Math.random() > 0.5) {
|
|
3063
|
+
throw new Error();
|
|
3064
|
+
}
|
|
3065
|
+
return new Author();
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
try {
|
|
3069
|
+
return findAuthor(); // succeed or fail
|
|
3070
|
+
} catch(error) {
|
|
3071
|
+
return findOtherAuther();
|
|
3072
|
+
} finally {
|
|
3073
|
+
// always runs
|
|
3074
|
+
// doesn't affect the return value
|
|
3075
|
+
}
|
|
3076
|
+
```
|
|
3077
|
+
|
|
3078
|
+
Asynchronous example:
|
|
3079
|
+
|
|
3080
|
+
```js
|
|
3081
|
+
findAuthor().catch(function(reason){
|
|
3082
|
+
return findOtherAuther();
|
|
3083
|
+
}).finally(function(){
|
|
3084
|
+
// author was either found, or not
|
|
3085
|
+
});
|
|
3086
|
+
```
|
|
3087
|
+
|
|
3088
|
+
@method finally
|
|
3089
|
+
@param {Function} callback
|
|
3090
|
+
@return {Promise}
|
|
3091
|
+
*/
|
|
2846
3092
|
|
|
2847
|
-
var Enumerator = function () {
|
|
2848
|
-
function Enumerator(Constructor, input) {
|
|
2849
|
-
this._instanceConstructor = Constructor;
|
|
2850
|
-
this.promise = new Constructor(noop);
|
|
2851
3093
|
|
|
2852
|
-
|
|
2853
|
-
|
|
3094
|
+
Promise.prototype.finally = function _finally(callback) {
|
|
3095
|
+
var promise = this;
|
|
3096
|
+
var constructor = promise.constructor;
|
|
3097
|
+
|
|
3098
|
+
if (isFunction(callback)) {
|
|
3099
|
+
return promise.then(function (value) {
|
|
3100
|
+
return constructor.resolve(callback()).then(function () {
|
|
3101
|
+
return value;
|
|
3102
|
+
});
|
|
3103
|
+
}, function (reason) {
|
|
3104
|
+
return constructor.resolve(callback()).then(function () {
|
|
3105
|
+
throw reason;
|
|
3106
|
+
});
|
|
3107
|
+
});
|
|
2854
3108
|
}
|
|
2855
3109
|
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
this._remaining = input.length;
|
|
3110
|
+
return promise.then(callback, callback);
|
|
3111
|
+
};
|
|
2859
3112
|
|
|
2860
|
-
|
|
3113
|
+
return Promise;
|
|
3114
|
+
}();
|
|
2861
3115
|
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
3116
|
+
Promise$1.prototype.then = then;
|
|
3117
|
+
Promise$1.all = all;
|
|
3118
|
+
Promise$1.race = race;
|
|
3119
|
+
Promise$1.resolve = resolve$1;
|
|
3120
|
+
Promise$1.reject = reject$1;
|
|
3121
|
+
Promise$1._setScheduler = setScheduler;
|
|
3122
|
+
Promise$1._setAsap = setAsap;
|
|
3123
|
+
Promise$1._asap = asap;
|
|
3124
|
+
|
|
3125
|
+
/*global self*/
|
|
3126
|
+
function polyfill() {
|
|
3127
|
+
var local = void 0;
|
|
3128
|
+
|
|
3129
|
+
if (typeof commonjsGlobal !== 'undefined') {
|
|
3130
|
+
local = commonjsGlobal;
|
|
3131
|
+
} else if (typeof self !== 'undefined') {
|
|
3132
|
+
local = self;
|
|
3133
|
+
} else {
|
|
3134
|
+
try {
|
|
3135
|
+
local = Function('return this')();
|
|
3136
|
+
} catch (e) {
|
|
3137
|
+
throw new Error('polyfill failed because global object is unavailable in this environment');
|
|
2873
3138
|
}
|
|
2874
3139
|
}
|
|
2875
3140
|
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
3141
|
+
var P = local.Promise;
|
|
3142
|
+
|
|
3143
|
+
if (P) {
|
|
3144
|
+
var promiseToString = null;
|
|
3145
|
+
try {
|
|
3146
|
+
promiseToString = Object.prototype.toString.call(P.resolve());
|
|
3147
|
+
} catch (e) {
|
|
3148
|
+
// silently ignored
|
|
2879
3149
|
}
|
|
2880
|
-
};
|
|
2881
3150
|
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
3151
|
+
if (promiseToString === '[object Promise]' && !P.cast) {
|
|
3152
|
+
return;
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
|
|
3156
|
+
local.Promise = Promise$1;
|
|
3157
|
+
}
|
|
2885
3158
|
|
|
3159
|
+
// Strange compat..
|
|
3160
|
+
Promise$1.polyfill = polyfill;
|
|
3161
|
+
Promise$1.Promise = Promise$1;
|
|
2886
3162
|
|
|
2887
|
-
|
|
2888
|
-
var _then = void 0;
|
|
2889
|
-
var error = void 0;
|
|
2890
|
-
var didError = false;
|
|
2891
|
-
try {
|
|
2892
|
-
_then = entry.then;
|
|
2893
|
-
} catch (e) {
|
|
2894
|
-
didError = true;
|
|
2895
|
-
error = e;
|
|
2896
|
-
}
|
|
3163
|
+
return Promise$1;
|
|
2897
3164
|
|
|
2898
|
-
|
|
2899
|
-
this._settledAt(entry._state, i, entry._result);
|
|
2900
|
-
} else if (typeof _then !== 'function') {
|
|
2901
|
-
this._remaining--;
|
|
2902
|
-
this._result[i] = entry;
|
|
2903
|
-
} else if (c === Promise$1) {
|
|
2904
|
-
var promise = new c(noop);
|
|
2905
|
-
if (didError) {
|
|
2906
|
-
reject(promise, error);
|
|
2907
|
-
} else {
|
|
2908
|
-
handleMaybeThenable(promise, entry, _then);
|
|
2909
|
-
}
|
|
2910
|
-
this._willSettleAt(promise, i);
|
|
2911
|
-
} else {
|
|
2912
|
-
this._willSettleAt(new c(function (resolve$$1) {
|
|
2913
|
-
return resolve$$1(entry);
|
|
2914
|
-
}), i);
|
|
2915
|
-
}
|
|
2916
|
-
} else {
|
|
2917
|
-
this._willSettleAt(resolve$$1(entry), i);
|
|
2918
|
-
}
|
|
2919
|
-
};
|
|
3165
|
+
})));
|
|
2920
3166
|
|
|
2921
|
-
Enumerator.prototype._settledAt = function _settledAt(state, i, value) {
|
|
2922
|
-
var promise = this.promise;
|
|
2923
3167
|
|
|
2924
3168
|
|
|
2925
|
-
if (promise._state === PENDING) {
|
|
2926
|
-
this._remaining--;
|
|
2927
3169
|
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
3170
|
+
});
|
|
3171
|
+
|
|
3172
|
+
var __extends = undefined && undefined.__extends || function () {
|
|
3173
|
+
var _extendStatics = function extendStatics(d, b) {
|
|
3174
|
+
_extendStatics = Object.setPrototypeOf || {
|
|
3175
|
+
__proto__: []
|
|
3176
|
+
} instanceof Array && function (d, b) {
|
|
3177
|
+
d.__proto__ = b;
|
|
3178
|
+
} || function (d, b) {
|
|
3179
|
+
for (var p in b) {
|
|
3180
|
+
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
2932
3181
|
}
|
|
2933
|
-
}
|
|
3182
|
+
};
|
|
2934
3183
|
|
|
2935
|
-
|
|
2936
|
-
fulfill(promise, this._result);
|
|
2937
|
-
}
|
|
3184
|
+
return _extendStatics(d, b);
|
|
2938
3185
|
};
|
|
2939
3186
|
|
|
2940
|
-
|
|
2941
|
-
|
|
3187
|
+
return function (d, b) {
|
|
3188
|
+
_extendStatics(d, b);
|
|
2942
3189
|
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
}
|
|
2946
|
-
return enumerator._settledAt(REJECTED, i, reason);
|
|
2947
|
-
});
|
|
2948
|
-
};
|
|
3190
|
+
function __() {
|
|
3191
|
+
this.constructor = d;
|
|
3192
|
+
}
|
|
2949
3193
|
|
|
2950
|
-
|
|
3194
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
3195
|
+
};
|
|
2951
3196
|
}();
|
|
2952
3197
|
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
elements of the passed iterable to promises as it runs this algorithm.
|
|
3198
|
+
var __assign$1 = undefined && undefined.__assign || function () {
|
|
3199
|
+
__assign$1 = Object.assign || function (t) {
|
|
3200
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
3201
|
+
s = arguments[i];
|
|
2958
3202
|
|
|
2959
|
-
|
|
3203
|
+
for (var p in s) {
|
|
3204
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
3205
|
+
}
|
|
3206
|
+
}
|
|
2960
3207
|
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
let promise2 = resolve(2);
|
|
2964
|
-
let promise3 = resolve(3);
|
|
2965
|
-
let promises = [ promise1, promise2, promise3 ];
|
|
3208
|
+
return t;
|
|
3209
|
+
};
|
|
2966
3210
|
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
});
|
|
2970
|
-
```
|
|
3211
|
+
return __assign$1.apply(this, arguments);
|
|
3212
|
+
};
|
|
2971
3213
|
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
rejection handler. For example:
|
|
3214
|
+
var __rest = undefined && undefined.__rest || function (s, e) {
|
|
3215
|
+
var t = {};
|
|
2975
3216
|
|
|
2976
|
-
|
|
3217
|
+
for (var p in s) {
|
|
3218
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
3219
|
+
}
|
|
2977
3220
|
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
3221
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
3222
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
3223
|
+
}
|
|
3224
|
+
return t;
|
|
3225
|
+
}; // eslint-disable-next-line max-classes-per-file
|
|
2983
3226
|
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
```
|
|
3227
|
+
var BaseValidator =
|
|
3228
|
+
/** @class */
|
|
3229
|
+
function () {
|
|
3230
|
+
function BaseValidator(value, rule, options) {
|
|
3231
|
+
this.value = value;
|
|
2990
3232
|
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
@param {String} label optional string for labeling the promise.
|
|
2995
|
-
Useful for tooling.
|
|
2996
|
-
@return {Promise} promise that is fulfilled when all `promises` have been
|
|
2997
|
-
fulfilled, or rejected if any of them become rejected.
|
|
2998
|
-
@static
|
|
2999
|
-
*/
|
|
3000
|
-
function all(entries) {
|
|
3001
|
-
return new Enumerator(this, entries).promise;
|
|
3002
|
-
}
|
|
3233
|
+
var _a = rule.message,
|
|
3234
|
+
message = _a === void 0 ? '' : _a,
|
|
3235
|
+
rest = __rest(rule, ["message"]);
|
|
3003
3236
|
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3237
|
+
this.message = message || '';
|
|
3238
|
+
this.type = rule.type || ValidatorType.String;
|
|
3239
|
+
this.error = {
|
|
3240
|
+
value: value,
|
|
3241
|
+
message: [],
|
|
3242
|
+
errorTypes: []
|
|
3243
|
+
};
|
|
3244
|
+
this.field = options.field || '';
|
|
3245
|
+
this.rule = rest;
|
|
3246
|
+
this.validateRules = [];
|
|
3247
|
+
this.curValidMsgTemplate = mergeMsgTemplate(messageTemplate, options.validateMessage);
|
|
3248
|
+
}
|
|
3007
3249
|
|
|
3008
|
-
|
|
3250
|
+
BaseValidator.prototype.isRequired = function () {
|
|
3251
|
+
// 优先级最高
|
|
3252
|
+
if (isEmptyValue(this.value) || isEmptyArray(this.value)) {
|
|
3253
|
+
this.error.message = [this.message || getMsgTemplate(this.curValidMsgTemplate, 'required', [this.field])];
|
|
3254
|
+
this.error.errorTypes = ['required'];
|
|
3255
|
+
return false;
|
|
3256
|
+
}
|
|
3009
3257
|
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
setTimeout(function(){
|
|
3013
|
-
resolve('promise 1');
|
|
3014
|
-
}, 200);
|
|
3015
|
-
});
|
|
3258
|
+
return true;
|
|
3259
|
+
};
|
|
3016
3260
|
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
resolve('promise 2');
|
|
3020
|
-
}, 100);
|
|
3021
|
-
});
|
|
3261
|
+
BaseValidator.prototype.addError = function (errorType, message) {
|
|
3262
|
+
var _a;
|
|
3022
3263
|
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3264
|
+
if (message) {
|
|
3265
|
+
this.error.errorTypes.push(errorType);
|
|
3266
|
+
(_a = this.error.message) === null || _a === void 0 ? void 0 : _a.push(message);
|
|
3267
|
+
}
|
|
3268
|
+
};
|
|
3028
3269
|
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
`promises` array argument are resolved, but the first settled promise has
|
|
3032
|
-
become rejected before the other promises became fulfilled, the returned
|
|
3033
|
-
promise will become rejected:
|
|
3270
|
+
BaseValidator.prototype.dealError = function (isError, _a) {
|
|
3271
|
+
var _b;
|
|
3034
3272
|
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
setTimeout(function(){
|
|
3038
|
-
resolve('promise 1');
|
|
3039
|
-
}, 200);
|
|
3040
|
-
});
|
|
3273
|
+
var errTemplate = _a.errTemplate,
|
|
3274
|
+
values = _a.values;
|
|
3041
3275
|
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3276
|
+
if (isError) {
|
|
3277
|
+
var theMessage = this.message || getMsgTemplate(this.curValidMsgTemplate, errTemplate, values);
|
|
3278
|
+
this.error.errorTypes.push(errTemplate);
|
|
3279
|
+
(_b = this.error.message) === null || _b === void 0 ? void 0 : _b.push(theMessage);
|
|
3280
|
+
return theMessage;
|
|
3281
|
+
}
|
|
3047
3282
|
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
}, function(reason){
|
|
3051
|
-
// reason.message === 'promise 2' because promise 2 became rejected before
|
|
3052
|
-
// promise 1 became fulfilled
|
|
3053
|
-
});
|
|
3054
|
-
```
|
|
3283
|
+
return '';
|
|
3284
|
+
};
|
|
3055
3285
|
|
|
3056
|
-
|
|
3286
|
+
BaseValidator.prototype.getErrors = function () {
|
|
3287
|
+
return this.error;
|
|
3288
|
+
};
|
|
3057
3289
|
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
```
|
|
3290
|
+
return BaseValidator;
|
|
3291
|
+
}();
|
|
3061
3292
|
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
@return {Promise} a promise which settles in the same way as the first passed
|
|
3067
|
-
promise to settle.
|
|
3068
|
-
*/
|
|
3069
|
-
function race(entries) {
|
|
3070
|
-
/*jshint validthis:true */
|
|
3071
|
-
var Constructor = this;
|
|
3293
|
+
var BooleanValidator =
|
|
3294
|
+
/** @class */
|
|
3295
|
+
function (_super) {
|
|
3296
|
+
__extends(BooleanValidator, _super);
|
|
3072
3297
|
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
return reject(new TypeError('You must pass an array to race.'));
|
|
3076
|
-
});
|
|
3077
|
-
} else {
|
|
3078
|
-
return new Constructor(function (resolve, reject) {
|
|
3079
|
-
var length = entries.length;
|
|
3080
|
-
for (var i = 0; i < length; i++) {
|
|
3081
|
-
Constructor.resolve(entries[i]).then(resolve, reject);
|
|
3082
|
-
}
|
|
3083
|
-
});
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3298
|
+
function BooleanValidator(value, rules, options) {
|
|
3299
|
+
var _this = _super.call(this, value, rules, options) || this;
|
|
3086
3300
|
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3301
|
+
_this.validateRules = ['equal'];
|
|
3302
|
+
return _this;
|
|
3303
|
+
}
|
|
3090
3304
|
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3305
|
+
BooleanValidator.prototype.equal = function (str) {
|
|
3306
|
+
return this.dealError(!isEmptyValue(this.value) && this.value !== str, {
|
|
3307
|
+
errTemplate: 'boolean.equal',
|
|
3308
|
+
values: [this.field, "" + str]
|
|
3309
|
+
});
|
|
3310
|
+
};
|
|
3095
3311
|
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
}, function(reason){
|
|
3099
|
-
// reason.message === 'WHOOPS'
|
|
3100
|
-
});
|
|
3101
|
-
```
|
|
3312
|
+
return BooleanValidator;
|
|
3313
|
+
}(BaseValidator);
|
|
3102
3314
|
|
|
3103
|
-
|
|
3315
|
+
var NumberValidator =
|
|
3316
|
+
/** @class */
|
|
3317
|
+
function (_super) {
|
|
3318
|
+
__extends(NumberValidator, _super);
|
|
3104
3319
|
|
|
3105
|
-
|
|
3106
|
-
|
|
3320
|
+
function NumberValidator(value, rules, options) {
|
|
3321
|
+
var _this = _super.call(this, value, rules, options) || this;
|
|
3107
3322
|
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
}
|
|
3111
|
-
// reason.message === 'WHOOPS'
|
|
3112
|
-
});
|
|
3113
|
-
```
|
|
3323
|
+
_this.validateRules = ['min', 'max', 'equal', 'positive', 'negative'];
|
|
3324
|
+
return _this;
|
|
3325
|
+
}
|
|
3114
3326
|
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
function reject$1(reason) {
|
|
3122
|
-
/*jshint validthis:true */
|
|
3123
|
-
var Constructor = this;
|
|
3124
|
-
var promise = new Constructor(noop);
|
|
3125
|
-
reject(promise, reason);
|
|
3126
|
-
return promise;
|
|
3127
|
-
}
|
|
3327
|
+
NumberValidator.prototype.min = function (num) {
|
|
3328
|
+
this.dealError(!isEmptyValue(this.value) && this.value < num, {
|
|
3329
|
+
errTemplate: 'number.min',
|
|
3330
|
+
values: [this.field, "" + num]
|
|
3331
|
+
});
|
|
3332
|
+
};
|
|
3128
3333
|
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3334
|
+
NumberValidator.prototype.max = function (num) {
|
|
3335
|
+
this.dealError(!isEmptyValue(this.value) && this.value > num, {
|
|
3336
|
+
errTemplate: 'number.max',
|
|
3337
|
+
values: [this.field, "" + num]
|
|
3338
|
+
});
|
|
3339
|
+
};
|
|
3132
3340
|
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3341
|
+
NumberValidator.prototype.equal = function (num) {
|
|
3342
|
+
return this.dealError(!isEmptyValue(this.value) && this.value !== num, {
|
|
3343
|
+
errTemplate: 'number.equal',
|
|
3344
|
+
values: [this.field, "" + num]
|
|
3345
|
+
});
|
|
3346
|
+
};
|
|
3136
3347
|
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3348
|
+
NumberValidator.prototype.positive = function () {
|
|
3349
|
+
return this.dealError(!isEmptyValue(this.value) && this.value < 0, {
|
|
3350
|
+
errTemplate: 'number.positive',
|
|
3351
|
+
values: [this.field]
|
|
3352
|
+
});
|
|
3353
|
+
};
|
|
3142
3354
|
|
|
3143
|
-
|
|
3144
|
-
|
|
3355
|
+
NumberValidator.prototype.negative = function () {
|
|
3356
|
+
return this.dealError(!isEmptyValue(this.value) && this.value > 0, {
|
|
3357
|
+
errTemplate: 'number.negative',
|
|
3358
|
+
values: [this.field]
|
|
3359
|
+
});
|
|
3360
|
+
};
|
|
3145
3361
|
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
|
|
3149
|
-
- `exception` is a value that is thrown using the throw statement.
|
|
3150
|
-
- `reason` is a value that indicates why a promise was rejected.
|
|
3151
|
-
- `settled` the final resting state of a promise, fulfilled or rejected.
|
|
3362
|
+
return NumberValidator;
|
|
3363
|
+
}(BaseValidator);
|
|
3152
3364
|
|
|
3153
|
-
|
|
3365
|
+
var StringValidator =
|
|
3366
|
+
/** @class */
|
|
3367
|
+
function (_super) {
|
|
3368
|
+
__extends(StringValidator, _super);
|
|
3154
3369
|
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
rejected state. A fulfillment value is never a thenable.
|
|
3158
|
-
|
|
3159
|
-
Promises can also be said to *resolve* a value. If this value is also a
|
|
3160
|
-
promise, then the original promise's settled state will match the value's
|
|
3161
|
-
settled state. So a promise that *resolves* a promise that rejects will
|
|
3162
|
-
itself reject, and a promise that *resolves* a promise that fulfills will
|
|
3163
|
-
itself fulfill.
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
Basic Usage:
|
|
3167
|
-
------------
|
|
3168
|
-
|
|
3169
|
-
```js
|
|
3170
|
-
let promise = new Promise(function(resolve, reject) {
|
|
3171
|
-
// on success
|
|
3172
|
-
resolve(value);
|
|
3173
|
-
|
|
3174
|
-
// on failure
|
|
3175
|
-
reject(reason);
|
|
3176
|
-
});
|
|
3177
|
-
|
|
3178
|
-
promise.then(function(value) {
|
|
3179
|
-
// on fulfillment
|
|
3180
|
-
}, function(reason) {
|
|
3181
|
-
// on rejection
|
|
3182
|
-
});
|
|
3183
|
-
```
|
|
3184
|
-
|
|
3185
|
-
Advanced Usage:
|
|
3186
|
-
---------------
|
|
3187
|
-
|
|
3188
|
-
Promises shine when abstracting away asynchronous interactions such as
|
|
3189
|
-
`XMLHttpRequest`s.
|
|
3190
|
-
|
|
3191
|
-
```js
|
|
3192
|
-
function getJSON(url) {
|
|
3193
|
-
return new Promise(function(resolve, reject){
|
|
3194
|
-
let xhr = new XMLHttpRequest();
|
|
3195
|
-
|
|
3196
|
-
xhr.open('GET', url);
|
|
3197
|
-
xhr.onreadystatechange = handler;
|
|
3198
|
-
xhr.responseType = 'json';
|
|
3199
|
-
xhr.setRequestHeader('Accept', 'application/json');
|
|
3200
|
-
xhr.send();
|
|
3370
|
+
function StringValidator(value, rules, options) {
|
|
3371
|
+
var _this = _super.call(this, value, rules, options) || this;
|
|
3201
3372
|
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
if (this.status === 200) {
|
|
3205
|
-
resolve(this.response);
|
|
3206
|
-
} else {
|
|
3207
|
-
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
|
3208
|
-
}
|
|
3209
|
-
}
|
|
3210
|
-
};
|
|
3211
|
-
});
|
|
3373
|
+
_this.validateRules = ['min', 'max', 'len', 'equal', 'match', 'uppercase', 'lowercase', 'whitespace'];
|
|
3374
|
+
return _this;
|
|
3212
3375
|
}
|
|
3213
3376
|
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
Unlike callbacks, promises are great composable primitives.
|
|
3222
|
-
|
|
3223
|
-
```js
|
|
3224
|
-
Promise.all([
|
|
3225
|
-
getJSON('/posts'),
|
|
3226
|
-
getJSON('/comments')
|
|
3227
|
-
]).then(function(values){
|
|
3228
|
-
values[0] // => postsJSON
|
|
3229
|
-
values[1] // => commentsJSON
|
|
3230
|
-
|
|
3231
|
-
return values;
|
|
3232
|
-
});
|
|
3233
|
-
```
|
|
3234
|
-
|
|
3235
|
-
@class Promise
|
|
3236
|
-
@param {Function} resolver
|
|
3237
|
-
Useful for tooling.
|
|
3238
|
-
@constructor
|
|
3239
|
-
*/
|
|
3240
|
-
|
|
3241
|
-
var Promise$1 = function () {
|
|
3242
|
-
function Promise(resolver) {
|
|
3243
|
-
this[PROMISE_ID] = nextId();
|
|
3244
|
-
this._result = this._state = undefined;
|
|
3245
|
-
this._subscribers = [];
|
|
3377
|
+
StringValidator.prototype.min = function (num) {
|
|
3378
|
+
return this.dealError(!isEmptyValue(this.value) && this.value.length < num, {
|
|
3379
|
+
errTemplate: 'string.min',
|
|
3380
|
+
values: [this.field, "" + num]
|
|
3381
|
+
});
|
|
3382
|
+
};
|
|
3246
3383
|
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3384
|
+
StringValidator.prototype.max = function (num) {
|
|
3385
|
+
return this.dealError(!isEmptyValue(this.value) && this.value.length > num, {
|
|
3386
|
+
errTemplate: 'string.max',
|
|
3387
|
+
values: [this.field, "" + num]
|
|
3388
|
+
});
|
|
3389
|
+
};
|
|
3252
3390
|
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
// user is available
|
|
3260
|
-
}, function(reason){
|
|
3261
|
-
// user is unavailable, and you are given the reason why
|
|
3262
|
-
});
|
|
3263
|
-
```
|
|
3264
|
-
Chaining
|
|
3265
|
-
--------
|
|
3266
|
-
The return value of `then` is itself a promise. This second, 'downstream'
|
|
3267
|
-
promise is resolved with the return value of the first promise's fulfillment
|
|
3268
|
-
or rejection handler, or rejected if the handler throws an exception.
|
|
3269
|
-
```js
|
|
3270
|
-
findUser().then(function (user) {
|
|
3271
|
-
return user.name;
|
|
3272
|
-
}, function (reason) {
|
|
3273
|
-
return 'default name';
|
|
3274
|
-
}).then(function (userName) {
|
|
3275
|
-
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
|
3276
|
-
// will be `'default name'`
|
|
3277
|
-
});
|
|
3278
|
-
findUser().then(function (user) {
|
|
3279
|
-
throw new Error('Found user, but still unhappy');
|
|
3280
|
-
}, function (reason) {
|
|
3281
|
-
throw new Error('`findUser` rejected and we're unhappy');
|
|
3282
|
-
}).then(function (value) {
|
|
3283
|
-
// never reached
|
|
3284
|
-
}, function (reason) {
|
|
3285
|
-
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
|
3286
|
-
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
|
|
3287
|
-
});
|
|
3288
|
-
```
|
|
3289
|
-
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
|
3290
|
-
```js
|
|
3291
|
-
findUser().then(function (user) {
|
|
3292
|
-
throw new PedagogicalException('Upstream error');
|
|
3293
|
-
}).then(function (value) {
|
|
3294
|
-
// never reached
|
|
3295
|
-
}).then(function (value) {
|
|
3296
|
-
// never reached
|
|
3297
|
-
}, function (reason) {
|
|
3298
|
-
// The `PedgagocialException` is propagated all the way down to here
|
|
3299
|
-
});
|
|
3300
|
-
```
|
|
3301
|
-
Assimilation
|
|
3302
|
-
------------
|
|
3303
|
-
Sometimes the value you want to propagate to a downstream promise can only be
|
|
3304
|
-
retrieved asynchronously. This can be achieved by returning a promise in the
|
|
3305
|
-
fulfillment or rejection handler. The downstream promise will then be pending
|
|
3306
|
-
until the returned promise is settled. This is called *assimilation*.
|
|
3307
|
-
```js
|
|
3308
|
-
findUser().then(function (user) {
|
|
3309
|
-
return findCommentsByAuthor(user);
|
|
3310
|
-
}).then(function (comments) {
|
|
3311
|
-
// The user's comments are now available
|
|
3312
|
-
});
|
|
3313
|
-
```
|
|
3314
|
-
If the assimliated promise rejects, then the downstream promise will also reject.
|
|
3315
|
-
```js
|
|
3316
|
-
findUser().then(function (user) {
|
|
3317
|
-
return findCommentsByAuthor(user);
|
|
3318
|
-
}).then(function (comments) {
|
|
3319
|
-
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
|
3320
|
-
}, function (reason) {
|
|
3321
|
-
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
|
3322
|
-
});
|
|
3323
|
-
```
|
|
3324
|
-
Simple Example
|
|
3325
|
-
--------------
|
|
3326
|
-
Synchronous Example
|
|
3327
|
-
```javascript
|
|
3328
|
-
let result;
|
|
3329
|
-
try {
|
|
3330
|
-
result = findResult();
|
|
3331
|
-
// success
|
|
3332
|
-
} catch(reason) {
|
|
3333
|
-
// failure
|
|
3334
|
-
}
|
|
3335
|
-
```
|
|
3336
|
-
Errback Example
|
|
3337
|
-
```js
|
|
3338
|
-
findResult(function(result, err){
|
|
3339
|
-
if (err) {
|
|
3340
|
-
// failure
|
|
3341
|
-
} else {
|
|
3342
|
-
// success
|
|
3343
|
-
}
|
|
3344
|
-
});
|
|
3345
|
-
```
|
|
3346
|
-
Promise Example;
|
|
3347
|
-
```javascript
|
|
3348
|
-
findResult().then(function(result){
|
|
3349
|
-
// success
|
|
3350
|
-
}, function(reason){
|
|
3351
|
-
// failure
|
|
3352
|
-
});
|
|
3353
|
-
```
|
|
3354
|
-
Advanced Example
|
|
3355
|
-
--------------
|
|
3356
|
-
Synchronous Example
|
|
3357
|
-
```javascript
|
|
3358
|
-
let author, books;
|
|
3359
|
-
try {
|
|
3360
|
-
author = findAuthor();
|
|
3361
|
-
books = findBooksByAuthor(author);
|
|
3362
|
-
// success
|
|
3363
|
-
} catch(reason) {
|
|
3364
|
-
// failure
|
|
3365
|
-
}
|
|
3366
|
-
```
|
|
3367
|
-
Errback Example
|
|
3368
|
-
```js
|
|
3369
|
-
function foundBooks(books) {
|
|
3370
|
-
}
|
|
3371
|
-
function failure(reason) {
|
|
3372
|
-
}
|
|
3373
|
-
findAuthor(function(author, err){
|
|
3374
|
-
if (err) {
|
|
3375
|
-
failure(err);
|
|
3376
|
-
// failure
|
|
3377
|
-
} else {
|
|
3378
|
-
try {
|
|
3379
|
-
findBoooksByAuthor(author, function(books, err) {
|
|
3380
|
-
if (err) {
|
|
3381
|
-
failure(err);
|
|
3382
|
-
} else {
|
|
3383
|
-
try {
|
|
3384
|
-
foundBooks(books);
|
|
3385
|
-
} catch(reason) {
|
|
3386
|
-
failure(reason);
|
|
3387
|
-
}
|
|
3388
|
-
}
|
|
3389
|
-
});
|
|
3390
|
-
} catch(error) {
|
|
3391
|
-
failure(err);
|
|
3392
|
-
}
|
|
3393
|
-
// success
|
|
3394
|
-
}
|
|
3395
|
-
});
|
|
3396
|
-
```
|
|
3397
|
-
Promise Example;
|
|
3398
|
-
```javascript
|
|
3399
|
-
findAuthor().
|
|
3400
|
-
then(findBooksByAuthor).
|
|
3401
|
-
then(function(books){
|
|
3402
|
-
// found books
|
|
3403
|
-
}).catch(function(reason){
|
|
3404
|
-
// something went wrong
|
|
3405
|
-
});
|
|
3406
|
-
```
|
|
3407
|
-
@method then
|
|
3408
|
-
@param {Function} onFulfilled
|
|
3409
|
-
@param {Function} onRejected
|
|
3410
|
-
Useful for tooling.
|
|
3411
|
-
@return {Promise}
|
|
3412
|
-
*/
|
|
3391
|
+
StringValidator.prototype.len = function (num) {
|
|
3392
|
+
return this.dealError(!isEmptyValue(this.value) && this.value.length !== num, {
|
|
3393
|
+
errTemplate: 'string.len',
|
|
3394
|
+
values: [this.field, "" + num]
|
|
3395
|
+
});
|
|
3396
|
+
};
|
|
3413
3397
|
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
}
|
|
3421
|
-
// synchronous
|
|
3422
|
-
try {
|
|
3423
|
-
findAuthor();
|
|
3424
|
-
} catch(reason) {
|
|
3425
|
-
// something went wrong
|
|
3426
|
-
}
|
|
3427
|
-
// async with promises
|
|
3428
|
-
findAuthor().catch(function(reason){
|
|
3429
|
-
// something went wrong
|
|
3430
|
-
});
|
|
3431
|
-
```
|
|
3432
|
-
@method catch
|
|
3433
|
-
@param {Function} onRejection
|
|
3434
|
-
Useful for tooling.
|
|
3435
|
-
@return {Promise}
|
|
3436
|
-
*/
|
|
3398
|
+
StringValidator.prototype.equal = function (str) {
|
|
3399
|
+
return this.dealError(!isEmptyValue(this.value) && this.value !== str, {
|
|
3400
|
+
errTemplate: 'string.equal',
|
|
3401
|
+
values: [this.field, "" + str]
|
|
3402
|
+
});
|
|
3403
|
+
};
|
|
3437
3404
|
|
|
3405
|
+
StringValidator.prototype.match = function (regStr) {
|
|
3406
|
+
var reg = new RegExp(regStr);
|
|
3407
|
+
return this.dealError(!isEmptyValue(this.value) && !reg.test(this.value), {
|
|
3408
|
+
errTemplate: 'string.match',
|
|
3409
|
+
values: [this.field, regStr]
|
|
3410
|
+
});
|
|
3411
|
+
};
|
|
3438
3412
|
|
|
3439
|
-
|
|
3440
|
-
|
|
3413
|
+
StringValidator.prototype.uppercase = function (isValue) {
|
|
3414
|
+
var isUppercase = (this.value || '').toLocaleUpperCase() === this.value;
|
|
3415
|
+
return this.dealError(!isEmptyValue(this.value) && isUppercase !== isValue, {
|
|
3416
|
+
errTemplate: 'string.uppercase',
|
|
3417
|
+
values: [this.field]
|
|
3418
|
+
});
|
|
3441
3419
|
};
|
|
3442
3420
|
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
```js
|
|
3450
|
-
findAuthor() {
|
|
3451
|
-
if (Math.random() > 0.5) {
|
|
3452
|
-
throw new Error();
|
|
3453
|
-
}
|
|
3454
|
-
return new Author();
|
|
3455
|
-
}
|
|
3456
|
-
|
|
3457
|
-
try {
|
|
3458
|
-
return findAuthor(); // succeed or fail
|
|
3459
|
-
} catch(error) {
|
|
3460
|
-
return findOtherAuther();
|
|
3461
|
-
} finally {
|
|
3462
|
-
// always runs
|
|
3463
|
-
// doesn't affect the return value
|
|
3464
|
-
}
|
|
3465
|
-
```
|
|
3466
|
-
|
|
3467
|
-
Asynchronous example:
|
|
3468
|
-
|
|
3469
|
-
```js
|
|
3470
|
-
findAuthor().catch(function(reason){
|
|
3471
|
-
return findOtherAuther();
|
|
3472
|
-
}).finally(function(){
|
|
3473
|
-
// author was either found, or not
|
|
3421
|
+
StringValidator.prototype.lowercase = function (isValue) {
|
|
3422
|
+
var isLowercase = (this.value || '').toLocaleLowerCase() === this.value;
|
|
3423
|
+
return this.dealError(!isEmptyValue(this.value) && isLowercase !== isValue, {
|
|
3424
|
+
errTemplate: 'string.lowercase',
|
|
3425
|
+
values: [this.field]
|
|
3474
3426
|
});
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3427
|
+
};
|
|
3428
|
+
|
|
3429
|
+
StringValidator.prototype.whitespace = function () {
|
|
3430
|
+
return this.dealError(!isEmptyValue(this.value) && isEmptyValue(this.value.trim()), {
|
|
3431
|
+
errTemplate: 'string.whitespace',
|
|
3432
|
+
values: [this.field]
|
|
3433
|
+
});
|
|
3434
|
+
};
|
|
3481
3435
|
|
|
3436
|
+
return StringValidator;
|
|
3437
|
+
}(BaseValidator);
|
|
3482
3438
|
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3439
|
+
var ArrayValidator =
|
|
3440
|
+
/** @class */
|
|
3441
|
+
function (_super) {
|
|
3442
|
+
__extends(ArrayValidator, _super);
|
|
3486
3443
|
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
return constructor.resolve(callback()).then(function () {
|
|
3490
|
-
return value;
|
|
3491
|
-
});
|
|
3492
|
-
}, function (reason) {
|
|
3493
|
-
return constructor.resolve(callback()).then(function () {
|
|
3494
|
-
throw reason;
|
|
3495
|
-
});
|
|
3496
|
-
});
|
|
3497
|
-
}
|
|
3444
|
+
function ArrayValidator(value, rules, options) {
|
|
3445
|
+
var _this = _super.call(this, value, rules, options) || this;
|
|
3498
3446
|
|
|
3499
|
-
|
|
3447
|
+
_this.validateRules = ['min', 'max', 'deepEqual', 'includes'];
|
|
3448
|
+
return _this;
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3451
|
+
ArrayValidator.prototype.min = function (num) {
|
|
3452
|
+
return this.dealError(!isEmptyValue(this.value) && this.value.length < num, {
|
|
3453
|
+
errTemplate: 'array.min',
|
|
3454
|
+
values: [this.field, "" + num]
|
|
3455
|
+
});
|
|
3500
3456
|
};
|
|
3501
3457
|
|
|
3502
|
-
|
|
3503
|
-
|
|
3458
|
+
ArrayValidator.prototype.max = function (num) {
|
|
3459
|
+
return this.dealError(!isEmptyValue(this.value) && this.value.length > num, {
|
|
3460
|
+
errTemplate: 'array.max',
|
|
3461
|
+
values: [this.field, "" + num]
|
|
3462
|
+
});
|
|
3463
|
+
};
|
|
3504
3464
|
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
Promise$1._setAsap = setAsap;
|
|
3512
|
-
Promise$1._asap = asap;
|
|
3465
|
+
ArrayValidator.prototype.deepEqual = function (sub) {
|
|
3466
|
+
return this.dealError(!isDeepEqual(this.value, sub), {
|
|
3467
|
+
errTemplate: 'array.equal',
|
|
3468
|
+
values: [this.field, "" + JSON.stringify(sub)]
|
|
3469
|
+
});
|
|
3470
|
+
};
|
|
3513
3471
|
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
var local = void 0;
|
|
3472
|
+
ArrayValidator.prototype.includes = function (sub) {
|
|
3473
|
+
var _this = this;
|
|
3517
3474
|
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
} catch (e) {
|
|
3526
|
-
throw new Error('polyfill failed because global object is unavailable in this environment');
|
|
3527
|
-
}
|
|
3528
|
-
}
|
|
3475
|
+
return this.dealError(sub.some(function (el) {
|
|
3476
|
+
return !_this.value.includes(el);
|
|
3477
|
+
}), {
|
|
3478
|
+
errTemplate: 'array.includes',
|
|
3479
|
+
values: [this.field, "" + JSON.stringify(sub)]
|
|
3480
|
+
});
|
|
3481
|
+
};
|
|
3529
3482
|
|
|
3530
|
-
|
|
3483
|
+
return ArrayValidator;
|
|
3484
|
+
}(BaseValidator);
|
|
3531
3485
|
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
} catch (e) {
|
|
3537
|
-
// silently ignored
|
|
3538
|
-
}
|
|
3486
|
+
var ObjectValidator =
|
|
3487
|
+
/** @class */
|
|
3488
|
+
function (_super) {
|
|
3489
|
+
__extends(ObjectValidator, _super);
|
|
3539
3490
|
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3491
|
+
function ObjectValidator(value, rules, options) {
|
|
3492
|
+
var _this = _super.call(this, value, rules, options) || this;
|
|
3493
|
+
|
|
3494
|
+
_this.validateRules = ['deepEqual', 'hasKeys'];
|
|
3495
|
+
return _this;
|
|
3543
3496
|
}
|
|
3544
3497
|
|
|
3545
|
-
|
|
3546
|
-
|
|
3498
|
+
ObjectValidator.prototype.deepEqual = function (sub) {
|
|
3499
|
+
return this.dealError(!isDeepEqual(this.value, sub), {
|
|
3500
|
+
errTemplate: 'object.deepEqual',
|
|
3501
|
+
values: [this.field, "" + JSON.stringify(sub)]
|
|
3502
|
+
});
|
|
3503
|
+
};
|
|
3547
3504
|
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3505
|
+
ObjectValidator.prototype.hasKeys = function (keys) {
|
|
3506
|
+
var allKeys = isEmptyValue(this.value) ? [] : Object.keys(this.value);
|
|
3507
|
+
return this.dealError(!isEmptyValue(this.value) && keys.some(function (theKey) {
|
|
3508
|
+
return !allKeys.includes(theKey);
|
|
3509
|
+
}), {
|
|
3510
|
+
errTemplate: 'object.hasKeys',
|
|
3511
|
+
values: [this.field, "" + JSON.stringify(keys)]
|
|
3512
|
+
});
|
|
3513
|
+
};
|
|
3551
3514
|
|
|
3552
|
-
|
|
3515
|
+
return ObjectValidator;
|
|
3516
|
+
}(BaseValidator);
|
|
3553
3517
|
|
|
3554
|
-
|
|
3518
|
+
var CustomValidator =
|
|
3519
|
+
/** @class */
|
|
3520
|
+
function (_super) {
|
|
3521
|
+
__extends(CustomValidator, _super);
|
|
3555
3522
|
|
|
3523
|
+
function CustomValidator(value, rules, options) {
|
|
3524
|
+
return _super.call(this, value, rules, options) || this;
|
|
3525
|
+
}
|
|
3556
3526
|
|
|
3527
|
+
CustomValidator.prototype.validator = function (validatorTool) {
|
|
3528
|
+
var _this = this;
|
|
3557
3529
|
|
|
3530
|
+
if (validatorTool) {
|
|
3531
|
+
return new es6Promise$1.Promise(function (resolve) {
|
|
3532
|
+
var validateLevel = _this.rule.validateLevel || 'error';
|
|
3533
|
+
var ret = validatorTool(_this.value, function (message) {
|
|
3534
|
+
if (message === void 0) {
|
|
3535
|
+
message = '';
|
|
3536
|
+
}
|
|
3558
3537
|
|
|
3559
|
-
|
|
3538
|
+
return _this.addError('custom', message || '');
|
|
3539
|
+
});
|
|
3540
|
+
|
|
3541
|
+
if (ret && (ret === null || ret === void 0 ? void 0 : ret.then)) {
|
|
3542
|
+
ret.then(function () {
|
|
3543
|
+
return resolve(__assign$1(__assign$1({}, _this.getErrors()), {
|
|
3544
|
+
validateLevel: validateLevel
|
|
3545
|
+
}));
|
|
3546
|
+
});
|
|
3547
|
+
} else {
|
|
3548
|
+
resolve(__assign$1(__assign$1({}, _this.getErrors()), {
|
|
3549
|
+
validateLevel: validateLevel
|
|
3550
|
+
}));
|
|
3551
|
+
}
|
|
3552
|
+
});
|
|
3553
|
+
}
|
|
3554
|
+
|
|
3555
|
+
return null;
|
|
3556
|
+
};
|
|
3557
|
+
|
|
3558
|
+
return CustomValidator;
|
|
3559
|
+
}(BaseValidator);
|
|
3560
3560
|
|
|
3561
3561
|
var __assign = undefined && undefined.__assign || function () {
|
|
3562
3562
|
__assign = Object.assign || function (t) {
|
|
@@ -9220,8 +9220,11 @@
|
|
|
9220
9220
|
otherProps = __rest$1(props, ["className", "items", "cancelText", "close", "title", "subTitle", "needBottomOffset"]);
|
|
9221
9221
|
|
|
9222
9222
|
var popupRef = React.useRef(null);
|
|
9223
|
+
var listRef = React.useRef(null);
|
|
9223
9224
|
React.useImperativeHandle(ref, function () {
|
|
9224
|
-
return popupRef.current
|
|
9225
|
+
return __assign$3(__assign$3({}, popupRef.current), {
|
|
9226
|
+
actionList: listRef.current
|
|
9227
|
+
});
|
|
9225
9228
|
});
|
|
9226
9229
|
|
|
9227
9230
|
function handleItemClick(e, item) {
|
|
@@ -9258,7 +9261,8 @@
|
|
|
9258
9261
|
}, title) : null, subTitle ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
9259
9262
|
className: prefixCls + "-action-sheet-sub-title"
|
|
9260
9263
|
}, subTitle) : null) : null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
9261
|
-
className: prefixCls + "-action-sheet-list"
|
|
9264
|
+
className: prefixCls + "-action-sheet-list",
|
|
9265
|
+
ref: listRef
|
|
9262
9266
|
}, (items || []).map(function (item, index) {
|
|
9263
9267
|
return item.content ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
9264
9268
|
className: cls(prefixCls + "-action-sheet-item", item.className, item.status || 'normal'),
|
|
@@ -11466,28 +11470,57 @@
|
|
|
11466
11470
|
append = props.append,
|
|
11467
11471
|
_b = props.bordered,
|
|
11468
11472
|
bordered = _b === void 0 ? true : _b,
|
|
11469
|
-
|
|
11473
|
+
onClick = props.onClick,
|
|
11474
|
+
_c = props.clickable,
|
|
11475
|
+
clickable = _c === void 0 ? false : _c;
|
|
11470
11476
|
var domRef = React.useRef(null);
|
|
11477
|
+
|
|
11478
|
+
var _d = React.useState(false),
|
|
11479
|
+
isPressed = _d[0],
|
|
11480
|
+
setIsPressed = _d[1];
|
|
11481
|
+
|
|
11471
11482
|
React.useImperativeHandle(ref, function () {
|
|
11472
11483
|
return {
|
|
11473
11484
|
dom: domRef.current
|
|
11474
11485
|
};
|
|
11475
11486
|
});
|
|
11487
|
+
|
|
11488
|
+
var handleTouchStart = function handleTouchStart() {
|
|
11489
|
+
if (clickable) {
|
|
11490
|
+
setIsPressed(true);
|
|
11491
|
+
}
|
|
11492
|
+
};
|
|
11493
|
+
|
|
11494
|
+
var handleTouchEnd = function handleTouchEnd() {
|
|
11495
|
+
if (clickable) {
|
|
11496
|
+
setIsPressed(false);
|
|
11497
|
+
}
|
|
11498
|
+
};
|
|
11499
|
+
|
|
11500
|
+
var handleClick = function handleClick(e) {
|
|
11501
|
+
if (onClick) {
|
|
11502
|
+
onClick(e);
|
|
11503
|
+
}
|
|
11504
|
+
};
|
|
11505
|
+
|
|
11476
11506
|
return /*#__PURE__*/React__default["default"].createElement(ContextLayout, null, function (_a) {
|
|
11477
11507
|
var prefixCls = _a.prefixCls;
|
|
11478
11508
|
return /*#__PURE__*/React__default["default"].createElement(GroupContext.Consumer, null, function (_a) {
|
|
11509
|
+
var _b, _c, _d;
|
|
11510
|
+
|
|
11479
11511
|
var isFromGroup = _a.isFromGroup;
|
|
11480
11512
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
11481
11513
|
className: cls(prefixCls + "-cell", 'all-border-box', {
|
|
11482
|
-
'without-group': !isFromGroup
|
|
11483
|
-
}, {
|
|
11484
11514
|
bordered: bordered
|
|
11485
|
-
},
|
|
11515
|
+
}, {
|
|
11516
|
+
'without-group': !isFromGroup
|
|
11517
|
+
}, (_b = {}, _b[prefixCls + "-cell-without-group"] = !isFromGroup, _b), (_c = {}, _c[prefixCls + "-cell-clickable"] = clickable, _c), (_d = {}, _d[prefixCls + "-cell-pressed"] = isPressed, _d), className),
|
|
11486
11518
|
style: style,
|
|
11487
11519
|
ref: domRef,
|
|
11488
|
-
onClick:
|
|
11489
|
-
|
|
11490
|
-
|
|
11520
|
+
onClick: handleClick,
|
|
11521
|
+
onTouchStart: handleTouchStart,
|
|
11522
|
+
onTouchEnd: handleTouchEnd,
|
|
11523
|
+
onTouchCancel: handleTouchEnd
|
|
11491
11524
|
}, prepend, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
11492
11525
|
className: cls(prefixCls + "-cell-inner", {
|
|
11493
11526
|
'has-desc': desc
|
|
@@ -14254,6 +14287,9 @@
|
|
|
14254
14287
|
React.useEffect(function () {
|
|
14255
14288
|
_updateRangeValue(currentTs);
|
|
14256
14289
|
}, [currentTs]);
|
|
14290
|
+
React.useEffect(function () {
|
|
14291
|
+
setCurrentTs(isRange ? Math.min(maxTs, Math.max(minTs, userSetCurrentTs[0])) : Math.min(maxTs, Math.max(minTs, userSetCurrentTs)));
|
|
14292
|
+
}, [userSetCurrentTs, maxTs, minTs, isRange]);
|
|
14257
14293
|
React.useEffect(function () {
|
|
14258
14294
|
if (visible) {
|
|
14259
14295
|
// 初始化当前时间
|
|
@@ -20964,7 +21000,7 @@
|
|
|
20964
21000
|
warnings: warnings,
|
|
20965
21001
|
errorTypes: errorTypes
|
|
20966
21002
|
});
|
|
20967
|
-
|
|
21003
|
+
resolve({
|
|
20968
21004
|
errors: _this._errors,
|
|
20969
21005
|
warnings: warnings,
|
|
20970
21006
|
value: value,
|
|
@@ -28950,7 +28986,7 @@
|
|
|
28950
28986
|
}, [disabled, ifShouldHandle]);
|
|
28951
28987
|
|
|
28952
28988
|
var refresh = function refresh() {
|
|
28953
|
-
return new Promise(function (resolve) {
|
|
28989
|
+
return new es6Promise.Promise(function (resolve) {
|
|
28954
28990
|
if (domRef.current) {
|
|
28955
28991
|
domRef.current.style.overflow = 'hidden';
|
|
28956
28992
|
var animationKey_1 = new Date().getTime();
|