Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit 22b8e56

Browse files
Updating to 5.0
1 parent 21710d0 commit 22b8e56

19 files changed

+407
-209
lines changed

dist/rx.dom.compat.js

+60-34
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@
463463
})();
464464

465465
/**
466-
* Creates a cold observable JSONP Request with the specified settings.
466+
* Creates an observable JSONP Request with the specified settings.
467467
*
468468
* @example
469469
* source = Rx.DOM.jsonpRequest('http://www.bing.com/?q=foo&JSONPCallback=?');
@@ -792,13 +792,34 @@
792792
/**
793793
* Scheduler that uses a MutationObserver changes as the scheduling mechanism
794794
*/
795-
Scheduler.mutationObserver = Scheduler.microtask = (function () {
795+
Scheduler.microtask = (function () {
796796

797-
function noop() {}
797+
var nextHandle = 1, tasksByHandle = {}, currentlyRunning = false, scheduleMethod;
798798

799-
var tasks = [], taskId = 0, scheduleMethod, clearMethod = noop;
799+
function clearMethod(handle) {
800+
delete tasksByHandle[handle];
801+
}
800802

801-
var setImmediate = root.setImmediate, clearImmediate = root.clearImmediate;
803+
function runTask(handle) {
804+
if (currentlyRunning) {
805+
root.setTimeout(function () { runTask(handle) }, 0);
806+
} else {
807+
var task = tasksByHandle[handle];
808+
if (task) {
809+
currentlyRunning = true;
810+
try {
811+
task();
812+
} catch (e) {
813+
throw e;
814+
} finally {
815+
clearMethod(handle);
816+
currentlyRunning = false;
817+
}
818+
}
819+
}
820+
}
821+
822+
var setImmediate = root.setImmediate;
802823

803824
function postMessageSupported () {
804825
// Ensure not in a worker
@@ -816,12 +837,12 @@
816837
var BrowserMutationObserver = root.MutationObserver || root.WebKitMutationObserver;
817838
if (!!BrowserMutationObserver) {
818839

819-
var observer = new BrowserMutationObserver(function() {
820-
var toProcess = tasks.slice(0);
840+
var PREFIX = 'drainqueue_';
821841

822-
toProcess.forEach(function (func) {
823-
func();
824-
});
842+
var observer = new BrowserMutationObserver(function(mutations) {
843+
mutations.forEach(function (mutation) {
844+
runTask(mutation.attributeName.substring(PREFIX.length));
845+
})
825846
});
826847

827848
var element = document.createElement('div');
@@ -834,71 +855,76 @@
834855
}, false);
835856

836857
scheduleMethod = function (action) {
837-
var id = taskId++;
838-
tasks[id] = action;
839-
element.setAttribute('drainQueue', 'drainQueue');
858+
var id = nextHandle++;
859+
tasksByHandle[id] = action;
860+
element.setAttribute(PREFIX + id, 'drainQueue');
840861
return id;
841862
};
842-
843-
var clearMethod = function(id) {
844-
delete tasks[id];
845-
};
846863
} else if (typeof setImmediate === 'function') {
847864
scheduleMethod = setImmediate;
848-
clearMethod = clearImmediate;
849865
} else if (postMessageSupported()) {
850866
var MSG_PREFIX = 'ms.rx.schedule' + Math.random();
851867

852-
var onGlobalPostMessage = function (event) {
868+
function onGlobalPostMessage(event) {
853869
// Only if we're a match to avoid any other global events
854870
if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
855-
var handleId = event.data.substring(MSG_PREFIX.length), action = tasks[handleId];
856-
action();
857-
tasks[handleId] = undefined;
871+
runTask(event.data.substring(MSG_PREFIX.length));
858872
}
859873
}
860874

861875
if (root.addEventListener) {
862876
root.addEventListener('message', onGlobalPostMessage, false);
863-
} else {
864-
root.attachEvent('onmessage', onGlobalPostMessage, false);
877+
} else if (root.attachEvent){
878+
root.attachEvent('onmessage', onGlobalPostMessage);
865879
}
866880

867881
scheduleMethod = function (action) {
868-
var currentId = taskId++;
869-
tasks[currentId] = action;
882+
var id = nextHandle++;
883+
tasksByHandle[currentId] = action;
870884
root.postMessage(MSG_PREFIX + currentId, '*');
885+
return id;
871886
};
872887
} else if (!!root.MessageChannel) {
873888
var channel = new root.MessageChannel();
874889

875890
channel.port1.onmessage = function (event) {
876-
var id = event.data, action = tasks[id];
877-
action();
878-
tasks[id] = undefined;
891+
runTask(event.data);
879892
};
880893

881894
scheduleMethod = function (action) {
882-
var id = taskId++;
883-
tasks[id] = action;
895+
var id = nextHandle++;
896+
tasksByHandle[id] = action;
884897
channel.port2.postMessage(id);
898+
return id;
885899
};
886900
} else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
887901

888902
scheduleMethod = function (action) {
889903
var scriptElement = root.document.createElement('script');
904+
var id = nextHandle++;
905+
tasksByHandle[id] = action;
906+
890907
scriptElement.onreadystatechange = function () {
891-
action();
908+
runTask(id);
892909
scriptElement.onreadystatechange = null;
893910
scriptElement.parentNode.removeChild(scriptElement);
894911
scriptElement = null;
895912
};
896913
root.document.documentElement.appendChild(scriptElement);
914+
915+
return id;
897916
};
898917

899918
} else {
900-
scheduleMethod = function (action) { return localSetTimeout(action, 0); };
901-
clearMethod = localClearTimeout;
919+
scheduleMethod = function (action) {
920+
var id = nextHandle++;
921+
tasksByHandle[id] = action;
922+
root.setTimeout(function () {
923+
runTask(id);
924+
}, 0);
925+
926+
return id;
927+
};
902928
}
903929

904930
function scheduleNow(state, action) {

dist/rx.dom.compat.map

+1-1
Large diffs are not rendered by default.

dist/rx.dom.compat.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.dom.js

+60-34
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@
385385
})();
386386

387387
/**
388-
* Creates a cold observable JSONP Request with the specified settings.
388+
* Creates an observable JSONP Request with the specified settings.
389389
*
390390
* @example
391391
* source = Rx.DOM.jsonpRequest('http://www.bing.com/?q=foo&JSONPCallback=?');
@@ -714,13 +714,34 @@
714714
/**
715715
* Scheduler that uses a MutationObserver changes as the scheduling mechanism
716716
*/
717-
Scheduler.mutationObserver = Scheduler.microtask = (function () {
717+
Scheduler.microtask = (function () {
718718

719-
function noop() {}
719+
var nextHandle = 1, tasksByHandle = {}, currentlyRunning = false, scheduleMethod;
720720

721-
var tasks = [], taskId = 0, scheduleMethod, clearMethod = noop;
721+
function clearMethod(handle) {
722+
delete tasksByHandle[handle];
723+
}
722724

723-
var setImmediate = root.setImmediate, clearImmediate = root.clearImmediate;
725+
function runTask(handle) {
726+
if (currentlyRunning) {
727+
root.setTimeout(function () { runTask(handle) }, 0);
728+
} else {
729+
var task = tasksByHandle[handle];
730+
if (task) {
731+
currentlyRunning = true;
732+
try {
733+
task();
734+
} catch (e) {
735+
throw e;
736+
} finally {
737+
clearMethod(handle);
738+
currentlyRunning = false;
739+
}
740+
}
741+
}
742+
}
743+
744+
var setImmediate = root.setImmediate;
724745

725746
function postMessageSupported () {
726747
// Ensure not in a worker
@@ -738,12 +759,12 @@
738759
var BrowserMutationObserver = root.MutationObserver || root.WebKitMutationObserver;
739760
if (!!BrowserMutationObserver) {
740761

741-
var observer = new BrowserMutationObserver(function() {
742-
var toProcess = tasks.slice(0);
762+
var PREFIX = 'drainqueue_';
743763

744-
toProcess.forEach(function (func) {
745-
func();
746-
});
764+
var observer = new BrowserMutationObserver(function(mutations) {
765+
mutations.forEach(function (mutation) {
766+
runTask(mutation.attributeName.substring(PREFIX.length));
767+
})
747768
});
748769

749770
var element = document.createElement('div');
@@ -756,71 +777,76 @@
756777
}, false);
757778

758779
scheduleMethod = function (action) {
759-
var id = taskId++;
760-
tasks[id] = action;
761-
element.setAttribute('drainQueue', 'drainQueue');
780+
var id = nextHandle++;
781+
tasksByHandle[id] = action;
782+
element.setAttribute(PREFIX + id, 'drainQueue');
762783
return id;
763784
};
764-
765-
var clearMethod = function(id) {
766-
delete tasks[id];
767-
};
768785
} else if (typeof setImmediate === 'function') {
769786
scheduleMethod = setImmediate;
770-
clearMethod = clearImmediate;
771787
} else if (postMessageSupported()) {
772788
var MSG_PREFIX = 'ms.rx.schedule' + Math.random();
773789

774-
var onGlobalPostMessage = function (event) {
790+
function onGlobalPostMessage(event) {
775791
// Only if we're a match to avoid any other global events
776792
if (typeof event.data === 'string' && event.data.substring(0, MSG_PREFIX.length) === MSG_PREFIX) {
777-
var handleId = event.data.substring(MSG_PREFIX.length), action = tasks[handleId];
778-
action();
779-
tasks[handleId] = undefined;
793+
runTask(event.data.substring(MSG_PREFIX.length));
780794
}
781795
}
782796

783797
if (root.addEventListener) {
784798
root.addEventListener('message', onGlobalPostMessage, false);
785-
} else {
786-
root.attachEvent('onmessage', onGlobalPostMessage, false);
799+
} else if (root.attachEvent){
800+
root.attachEvent('onmessage', onGlobalPostMessage);
787801
}
788802

789803
scheduleMethod = function (action) {
790-
var currentId = taskId++;
791-
tasks[currentId] = action;
804+
var id = nextHandle++;
805+
tasksByHandle[currentId] = action;
792806
root.postMessage(MSG_PREFIX + currentId, '*');
807+
return id;
793808
};
794809
} else if (!!root.MessageChannel) {
795810
var channel = new root.MessageChannel();
796811

797812
channel.port1.onmessage = function (event) {
798-
var id = event.data, action = tasks[id];
799-
action();
800-
tasks[id] = undefined;
813+
runTask(event.data);
801814
};
802815

803816
scheduleMethod = function (action) {
804-
var id = taskId++;
805-
tasks[id] = action;
817+
var id = nextHandle++;
818+
tasksByHandle[id] = action;
806819
channel.port2.postMessage(id);
820+
return id;
807821
};
808822
} else if ('document' in root && 'onreadystatechange' in root.document.createElement('script')) {
809823

810824
scheduleMethod = function (action) {
811825
var scriptElement = root.document.createElement('script');
826+
var id = nextHandle++;
827+
tasksByHandle[id] = action;
828+
812829
scriptElement.onreadystatechange = function () {
813-
action();
830+
runTask(id);
814831
scriptElement.onreadystatechange = null;
815832
scriptElement.parentNode.removeChild(scriptElement);
816833
scriptElement = null;
817834
};
818835
root.document.documentElement.appendChild(scriptElement);
836+
837+
return id;
819838
};
820839

821840
} else {
822-
scheduleMethod = function (action) { return localSetTimeout(action, 0); };
823-
clearMethod = localClearTimeout;
841+
scheduleMethod = function (action) {
842+
var id = nextHandle++;
843+
tasksByHandle[id] = action;
844+
root.setTimeout(function () {
845+
runTask(id);
846+
}, 0);
847+
848+
return id;
849+
};
824850
}
825851

826852
function scheduleNow(state, action) {

dist/rx.dom.map

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)