Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const observer = new ObserverFunc((mutations) => {
// The observerUpdate event should only be triggered
// once despite the number of mutations. Additional
// triggers are redundant and are very costly
if (mutations.length === 1) {
swiper.emit('observerUpdate', mutations[0]);
return;
}
const observerUpdate = function observerUpdate() {
swiper.emit('observerUpdate', mutations[0]);
};
if (window.requestAnimationFrame) {
window.requestAnimationFrame(observerUpdate);
} else {
window.setTimeout(observerUpdate, 0);
}
});
$startUpdateQueue() {
const self = this;
if (self.__requestAnimationFrameId) return;
function update() {
let html = self.$render();
// Make Dom
if (html && typeof html === 'string') {
html = html.trim();
const newVNode = vdom(html, self, false);
self.$vnode = patch(self.$vnode, newVNode);
}
}
self.__requestAnimationFrameId = window.requestAnimationFrame(() => {
if (self.__updateIsPending) update();
let resolvers = [...self.__updateQueue];
self.__updateQueue = [];
self.__updateIsPending = false;
window.cancelAnimationFrame(self.__requestAnimationFrameId);
delete self.__requestAnimationFrameId;
delete self.__updateIsPending;
resolvers.forEach(resolver => resolver());
resolvers = [];
});
}
$update() {
const self = this;
window.cancelAnimationFrame(self.__requestAnimationFrameId);
delete self.__requestAnimationFrameId;
self.__updateIsPending = true;
self.__requestAnimationFrameId = window.requestAnimationFrame(() => {
let html = self.$render();
// Make Dom
if (html && typeof html === 'string') {
html = html.trim();
const newVNode = vdom(html, self, false);
self.$vnode = patch(self.$vnode, newVNode);
}
self.__updateIsPending = false;
delete self.__updateIsPending;
});
}
function requestAnimationFrame(callback) {
if (window.requestAnimationFrame) return window.requestAnimationFrame(callback);
else if (window.webkitRequestAnimationFrame) return window.webkitRequestAnimationFrame(callback);
return window.setTimeout(callback, 1000 / 60);
}
function cancelAnimationFrame(id) {
function requestAnimationFrame(callback) {
if (window.requestAnimationFrame) return window.requestAnimationFrame(callback);
else if (window.webkitRequestAnimationFrame) return window.webkitRequestAnimationFrame(callback);
return window.setTimeout(callback, 1000 / 60);
}
function cancelAnimationFrame(id) {
requestAnimationFrame(callback) {
return window.requestAnimationFrame(callback);
},
cancelAnimationFrame(id) {
$tick(callback) {
const self = this;
window.requestAnimationFrame(() => {
if (self.__updateIsPending) {
window.requestAnimationFrame(() => {
callback();
});
} else {
callback();
}
});
}