Skip to content

Commit 93b14a1

Browse files
committed
jstree._append_json_data() callback always asynchronous, even when no worker is used
1 parent 3b90914 commit 93b14a1

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

dist/jstree.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@
4545
src = $('script:last').attr('src'),
4646
document = window.document; // local variable is always faster to access then a global
4747

48+
var setImmediate = window.setImmediate;
49+
var Promise = window.Promise;
50+
if (!setImmediate && Promise) {
51+
// Good enough approximation of setImmediate
52+
setImmediate = function (cb, arg) {
53+
Promise.resolve(arg).then(cb);
54+
};
55+
}
56+
4857
/**
4958
* holds all jstree related functions and variables, including the actual class and methods to create, access and manipulate instances.
5059
* @name $.jstree
@@ -1935,7 +1944,16 @@
19351944
if(rslt.add.length) {
19361945
this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
19371946
}
1938-
cb.call(this, true);
1947+
1948+
// If no worker, try to mimic worker behavioour, by invoking cb asynchronously
1949+
if (!worker && setImmediate) {
1950+
setImmediate(function(){
1951+
cb.call(inst, true);
1952+
});
1953+
}
1954+
else {
1955+
cb.call(inst, true);
1956+
}
19391957
};
19401958
if(this.settings.core.worker && window.Blob && window.URL && window.Worker) {
19411959
try {

src/jstree.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@
4545
src = $('script:last').attr('src'),
4646
document = window.document; // local variable is always faster to access then a global
4747

48+
var setImmediate = window.setImmediate;
49+
var Promise = window.Promise;
50+
if (!setImmediate && Promise) {
51+
// Good enough approximation of setImmediate
52+
setImmediate = function (cb, arg) {
53+
Promise.resolve(arg).then(cb);
54+
};
55+
}
56+
4857
/**
4958
* holds all jstree related functions and variables, including the actual class and methods to create, access and manipulate instances.
5059
* @name $.jstree
@@ -1935,7 +1944,16 @@
19351944
if(rslt.add.length) {
19361945
this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
19371946
}
1938-
cb.call(this, true);
1947+
1948+
// If no worker, try to mimic worker behavioour, by invoking cb asynchronously
1949+
if (!worker && setImmediate) {
1950+
setImmediate(function(){
1951+
cb.call(inst, true);
1952+
});
1953+
}
1954+
else {
1955+
cb.call(inst, true);
1956+
}
19391957
};
19401958
if(this.settings.core.worker && window.Blob && window.URL && window.Worker) {
19411959
try {

0 commit comments

Comments
 (0)