Browse Source

Merge pull request #1241 in VISUAL/fineui from ~WINDY/fineui:master to master

* commit '9588a6fae8b026dfb3f79b5d7971cb378c4c59e5':
  KERNEL-2905 refactor: title默认挂载到body与nextTick更新
master
windy 5 years ago
parent
commit
a0676e5c24
  1. 3
      dist/base.js
  2. 75
      dist/fix/fix.ie.js
  3. 67
      dist/fix/fix.js
  4. 3
      src/base/single/single.js
  5. 46
      src/core/base.js

3
dist/base.js vendored

@ -348,7 +348,8 @@ BI.Single = BI.inherit(BI.Widget, {
warningTitle: null, warningTitle: null,
tipType: null, // success或warning tipType: null, // success或warning
value: null, value: null,
belowMouse: false // title是否跟随鼠标 belowMouse: false, // title是否跟随鼠标
container: "body"
}); });
}, },

75
dist/fix/fix.ie.js vendored

@ -45,7 +45,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
args[_key] = arguments[_key]; args[_key] = arguments[_key];
} }
return originalMethods.splice.apply(this, args); return originalMethods["splice"].apply(this, args);
}; };
function noop(a, b, c) {} function noop(a, b, c) {}
@ -137,7 +137,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
} else { } else {
result = model; result = model;
} }
return result; return result;
} }
@ -147,7 +146,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
if (Array.isArray(obj)) { if (Array.isArray(obj)) {
var result = [].concat(obj); var result = [].concat(obj);
if (obj.__ref__ !== undefined) result.__ref__ = obj.__ref__; if (obj.__ref__ !== undefined) result.__ref__ = obj.__ref__;
return result; return result;
} }
@ -168,37 +166,55 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
} }
} }
// An asynchronous deferring mechanism. // Here we have async deferring wrappers using microtasks.
// In pre 2.4, we used to use microtasks (Promise/MutationObserver) // In 2.5 we used (macro) tasks (in combination with microtasks).
// but microtasks actually has too high a priority and fires in between // However, it has subtle problems when state is changed right before repaint
// supposedly sequential events (e.g. #4521, #6690) or even between // (e.g. #6813, out-in transitions).
// bubbling of the same event (#6566). Technically setImmediate should be // Also, using (macro) tasks in event handler would cause some weird behaviors
// the ideal choice, but it's not available everywhere; and the only polyfill // that cannot be circumvented (e.g. #7109, #7153, #7546, #7834, #8109).
// that consistently queues the callback after all DOM events triggered in the // So we now use microtasks everywhere, again.
// same loop is by using MessageChannel. // A major drawback of this tradeoff is that there are some scenarios
/* istanbul ignore if */ // where microtasks have too high a priority and fire in between supposedly
if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) { // sequential events (e.g. #4521, #6690, which have workarounds)
// or even between bubbling of the same event (#6566).
// The nextTick behavior leverages the microtask queue, which can be accessed
// via either native Promise.then or MutationObserver.
// MutationObserver has wider support, however it is seriously bugged in
// UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It
// completely stops working after triggering a few times... so, if native
// Promise is available, we will use it:
/* istanbul ignore next, $flow-disable-line */
if (typeof Promise !== 'undefined' && isNative(Promise)) {
var p = Promise.resolve();
timerFunc = function timerFunc() { timerFunc = function timerFunc() {
setImmediate(nextTickHandler); p.then(nextTickHandler);
}; };
} else if (typeof MessageChannel !== 'undefined' && (isNative(MessageChannel) || } else if (!isIE && typeof MutationObserver !== 'undefined' && (isNative(MutationObserver) ||
// PhantomJS // PhantomJS and iOS 7.x
MessageChannel.toString() === '[object MessageChannelConstructor]')) { MutationObserver.toString() === '[object MutationObserverConstructor]')) {
var channel = new MessageChannel(); // Use MutationObserver where native Promise is not available,
var port = channel.port2; // e.g. PhantomJS, iOS7, Android 4.4
channel.port1.onmessage = nextTickHandler; // (#6466 MutationObserver is unreliable in IE11)
var counter = 1;
var observer = new MutationObserver(nextTickHandler);
var textNode = document.createTextNode(String(counter));
observer.observe(textNode, {
characterData: true
});
timerFunc = function timerFunc() { timerFunc = function timerFunc() {
port.postMessage(1); counter = (counter + 1) % 2;
textNode.data = String(counter);
}; };
/* istanbul ignore next */ } else if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) {
} else if (typeof Promise !== 'undefined' && isNative(Promise)) { // Fallback to setImmediate.
// use microtask in non-DOM environments, e.g. Weex // Technically it leverages the (macro) task queue,
var p = Promise.resolve(); // but it is still a better choice than setTimeout.
timerFunc = function timerFunc() { timerFunc = function timerFunc() {
p.then(nextTickHandler); setImmediate(nextTickHandler);
}; };
} else { } else {
// fallback to setTimeout // Fallback to setTimeout.
timerFunc = function timerFunc() { timerFunc = function timerFunc() {
setTimeout(nextTickHandler, 0); setTimeout(nextTickHandler, 0);
}; };
@ -231,7 +247,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}(); }();
function inherit(sb, sp, overrides) { function inherit(sb, sp, overrides) {
if (typeof sp === 'object') { if (typeof sp === "object") {
overrides = sp; overrides = sp;
sp = sb; sp = sb;
sb = function temp() { sb = function temp() {
@ -246,7 +262,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
_$1.extend(sb.prototype, overrides, { _$1.extend(sb.prototype, overrides, {
superclass: sp superclass: sp
}); });
return sb; return sb;
} }
@ -916,7 +931,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}); });
if (contextListeners.length !== 0 || asyncListeners.length !== 0) { if (contextListeners.length !== 0 || asyncListeners.length !== 0) {
nextTick(function () { nextTick(function () {
_$1.each(BI.uniqBy(contextListeners.reverse(), 'id').reverse(), function (listener) { _$1.each(BI.uniqBy(contextListeners.reverse(), "id").reverse(), function (listener) {
listener.cb(); listener.cb();
}); });
_$1.each(asyncListeners, function (listener) { _$1.each(asyncListeners, function (listener) {

67
dist/fix/fix.js vendored

@ -120,38 +120,55 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
} }
} }
// An asynchronous deferring mechanism. // Here we have async deferring wrappers using microtasks.
// In pre 2.4, we used to use microtasks (Promise/MutationObserver) // In 2.5 we used (macro) tasks (in combination with microtasks).
// but microtasks actually has too high a priority and fires in between // However, it has subtle problems when state is changed right before repaint
// supposedly sequential events (e.g. #4521, #6690) or even between // (e.g. #6813, out-in transitions).
// bubbling of the same event (#6566). Technically setImmediate should be // Also, using (macro) tasks in event handler would cause some weird behaviors
// the ideal choice, but it's not available everywhere; and the only polyfill // that cannot be circumvented (e.g. #7109, #7153, #7546, #7834, #8109).
// that consistently queues the callback after all DOM events triggered in the // So we now use microtasks everywhere, again.
// same loop is by using MessageChannel. // A major drawback of this tradeoff is that there are some scenarios
/* istanbul ignore if */ // where microtasks have too high a priority and fire in between supposedly
if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) { // sequential events (e.g. #4521, #6690, which have workarounds)
// or even between bubbling of the same event (#6566).
// The nextTick behavior leverages the microtask queue, which can be accessed
// via either native Promise.then or MutationObserver.
// MutationObserver has wider support, however it is seriously bugged in
// UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It
// completely stops working after triggering a few times... so, if native
// Promise is available, we will use it:
/* istanbul ignore next, $flow-disable-line */
if (typeof Promise !== 'undefined' && isNative(Promise)) {
var p = Promise.resolve();
timerFunc = function timerFunc() { timerFunc = function timerFunc() {
setImmediate(nextTickHandler); p.then(nextTickHandler);
}; };
} else if (typeof MessageChannel !== 'undefined' && (isNative(MessageChannel) || } else if (!isIE && typeof MutationObserver !== 'undefined' && (isNative(MutationObserver) ||
// PhantomJS // PhantomJS and iOS 7.x
MessageChannel.toString() === '[object MessageChannelConstructor]')) { MutationObserver.toString() === '[object MutationObserverConstructor]')) {
var channel = new MessageChannel(); // Use MutationObserver where native Promise is not available,
var port = channel.port2; // e.g. PhantomJS, iOS7, Android 4.4
channel.port1.onmessage = nextTickHandler; // (#6466 MutationObserver is unreliable in IE11)
var counter = 1;
var observer = new MutationObserver(nextTickHandler);
var textNode = document.createTextNode(String(counter));
observer.observe(textNode, {
characterData: true
});
timerFunc = function timerFunc() { timerFunc = function timerFunc() {
port.postMessage(1); counter = (counter + 1) % 2;
textNode.data = String(counter);
}; };
} else } else if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) {
/* istanbul ignore next */ // Fallback to setImmediate.
if (typeof Promise !== 'undefined' && isNative(Promise)) { // Technically it leverages the (macro) task queue,
// use microtask in non-DOM environments, e.g. Weex // but it is still a better choice than setTimeout.
var p = Promise.resolve();
timerFunc = function timerFunc() { timerFunc = function timerFunc() {
p.then(nextTickHandler); setImmediate(nextTickHandler);
}; };
} else { } else {
// fallback to setTimeout // Fallback to setTimeout.
timerFunc = function timerFunc() { timerFunc = function timerFunc() {
setTimeout(nextTickHandler, 0); setTimeout(nextTickHandler, 0);
}; };

3
src/base/single/single.js

@ -19,7 +19,8 @@ BI.Single = BI.inherit(BI.Widget, {
warningTitle: null, warningTitle: null,
tipType: null, // success或warning tipType: null, // success或warning
value: null, value: null,
belowMouse: false // title是否跟随鼠标 belowMouse: false, // title是否跟随鼠标
container: "body"
}); });
}, },

46
src/core/base.js

@ -674,12 +674,12 @@ if (!_global.BI) {
nextTick: (function () { nextTick: (function () {
var callbacks = []; var callbacks = [];
var pending = false; var pending = false;
var timerFunc; var timerFunc = void 0;
function nextTickHandler () { function nextTickHandler() {
pending = false; pending = false;
var copies = callbacks.slice(0); var copies = callbacks.slice(0);
callbacks = []; callbacks.length = 0;
for (var i = 0; i < copies.length; i++) { for (var i = 0; i < copies.length; i++) {
copies[i](); copies[i]();
} }
@ -687,45 +687,51 @@ if (!_global.BI) {
if (typeof Promise !== "undefined") { if (typeof Promise !== "undefined") {
var p = Promise.resolve(); var p = Promise.resolve();
timerFunc = function () { timerFunc = function timerFunc() {
p.then(nextTickHandler); p.then(nextTickHandler);
}; };
} else } else if (!BI.isIE() && typeof MutationObserver !== "undefined") {
/* istanbul ignore if */
if (typeof MutationObserver !== "undefined") {
var counter = 1; var counter = 1;
var observer = new MutationObserver(nextTickHandler); var observer = new MutationObserver(nextTickHandler);
var textNode = document.createTextNode(counter + ""); var textNode = document.createTextNode(String(counter));
observer.observe(textNode, { observer.observe(textNode, {
characterData: true characterData: true
}); });
timerFunc = function () { timerFunc = function timerFunc() {
counter = (counter + 1) % 2; counter = (counter + 1) % 2;
textNode.data = counter + ""; textNode.data = String(counter);
};
} else if (typeof setImmediate !== "undefined") {
timerFunc = function timerFunc() {
setImmediate(nextTickHandler);
}; };
} else { } else {
timerFunc = function () { // Fallback to setTimeout.
timerFunc = function timerFunc() {
setTimeout(nextTickHandler, 0); setTimeout(nextTickHandler, 0);
}; };
} }
return function queueNextTick (cb) {
var _resolve; return function queueNextTick(cb, ctx) {
var args = [].slice.call(arguments, 1); var _resolve = void 0;
callbacks.push(function () { callbacks.push(function () {
if (cb) { if (cb) {
cb.apply(null, args); try {
cb.call(ctx);
} catch (e) {
console.error(e);
} }
if (_resolve) { } else if (_resolve) {
_resolve.apply(null, args); _resolve(ctx);
} }
}); });
if (!pending) { if (!pending) {
pending = true; pending = true;
timerFunc(); timerFunc();
} }
if (!cb && typeof Promise !== "undefined") { // $flow-disable-line
return new Promise(function (resolve) { if (!cb && typeof Promise !== 'undefined') {
return new Promise(function (resolve, reject) {
_resolve = resolve; _resolve = resolve;
}); });
} }

Loading…
Cancel
Save