Skip to content

Commit a99f664

Browse files
author
vvo
committed
fix(postMessage): avoid using postMessage when feasible
Before this commit, we were using setImmediate which was then polyfilled by webpack in a way that is not efficient and led to issues like #142 where postMessage was used no matter what. Now we use the `immediate` dependency which will first try to use nextTick, then mutation observers (IE11) then fallback to postMessage but in a way that should not bug any user registering for global messages. fixes #142
1 parent 4d5910a commit a99f664

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"grunt-step": "^1.0.0",
3939
"grunt-umd": "^2.3.6",
4040
"grunt-webpack": "^1.0.14",
41+
"immediate": "^3.2.3",
4142
"istanbul-instrumenter-loader": "^1.0.0",
4243
"jasmine-core": "^2.5.2",
4344
"jasmine-jquery": "^2.1.1",

src/autocomplete/event_emitter.js

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3+
var immediate = require('immediate');
34
var splitter = /\s+/;
4-
var nextTick = getNextTick();
55

66
module.exports = {
77
onSync: onSync,
@@ -73,7 +73,7 @@ function trigger(types) {
7373
asyncFlush = getFlush(callbacks.async, this, [type].concat(args));
7474

7575
if (syncFlush()) {
76-
nextTick(asyncFlush);
76+
immediate(asyncFlush);
7777
}
7878
}
7979

@@ -95,22 +95,6 @@ function getFlush(callbacks, context, args) {
9595
}
9696
}
9797

98-
function getNextTick() {
99-
var nextTickFn;
100-
101-
if (window.setImmediate) { // IE10+
102-
nextTickFn = function nextTickSetImmediate(fn) {
103-
setImmediate(function() { fn(); });
104-
};
105-
} else { // old browsers
106-
nextTickFn = function nextTickSetTimeout(fn) {
107-
setTimeout(function() { fn(); }, 0);
108-
};
109-
}
110-
111-
return nextTickFn;
112-
}
113-
11498
function bindContext(fn, context) {
11599
return fn.bind ?
116100
fn.bind(context) :

yarn.lock

+6-2
Original file line numberDiff line numberDiff line change
@@ -2527,6 +2527,10 @@ ieee754@^1.1.4:
25272527
version "1.1.8"
25282528
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4"
25292529

2530+
immediate@^3.2.3:
2531+
version "3.2.3"
2532+
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.2.3.tgz#d140fa8f614659bd6541233097ddaac25cdd991c"
2533+
25302534
indent-string@^2.0.0, indent-string@^2.1.0:
25312535
version "2.1.0"
25322536
resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-2.1.0.tgz#8e2d48348742121b4a8218b7a137e9a52049dc80"
@@ -3573,15 +3577,15 @@ [email protected], minimist@~0.0.1, minimist@~0.0.7:
35733577
version "0.0.8"
35743578
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
35753579

3576-
[email protected], minimist@^1.1.3, minimist@^1.2.0:
3580+
[email protected], minimist@^1.2.0:
35773581
version "1.2.0"
35783582
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
35793583

35803584
minimist@^0.2.0:
35813585
version "0.2.0"
35823586
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.2.0.tgz#4dffe525dae2b864c66c2e23c6271d7afdecefce"
35833587

3584-
minimist@~1.1.0:
3588+
minimist@^1.1.3, minimist@~1.1.0:
35853589
version "1.1.3"
35863590
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.1.3.tgz#3bedfd91a92d39016fcfaa1c681e8faa1a1efda8"
35873591

0 commit comments

Comments
 (0)