Parcourir la source

Merge pull request #545 from bep/pause-observer

Allow clients to pause the observer
Caleb Porzio il y a 5 ans
Parent
commit
ff8b1f4df4
3 fichiers modifiés avec 9 ajouts et 0 suppressions
  1. 3 0
      dist/alpine-ie11.js
  2. 3 0
      dist/alpine.js
  3. 3 0
      src/index.js

+ 3 - 0
dist/alpine-ie11.js

@@ -7235,6 +7235,7 @@
 
   var Alpine = {
     version: "2.3.5",
+    pauseObserver: false,
     start: function () {
       var _start = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
         var _this = this;
@@ -7329,6 +7330,8 @@
 
         _newArrowCheck(this, _this5);
 
+        if (this.pauseObserver) return;
+
         for (var i = 0; i < mutations.length; i++) {
           if (mutations[i].addedNodes.length > 0) {
             mutations[i].addedNodes.forEach(function (node) {

+ 3 - 0
dist/alpine.js

@@ -1676,6 +1676,7 @@
 
   const Alpine = {
     version: "2.3.5",
+    pauseObserver: false,
     start: async function start() {
       if (!isTesting()) {
         await domReady();
@@ -1715,6 +1716,8 @@
         subtree: true
       };
       const observer = new MutationObserver(mutations => {
+        if (this.pauseObserver) return;
+
         for (let i = 0; i < mutations.length; i++) {
           if (mutations[i].addedNodes.length > 0) {
             mutations[i].addedNodes.forEach(node => {

+ 3 - 0
src/index.js

@@ -3,6 +3,7 @@ import { domReady, isTesting } from './utils'
 
 const Alpine = {
     version: process.env.PKG_VERSION,
+    pauseObserver: false,
     start: async function () {
         if (! isTesting()) {
             await domReady()
@@ -53,6 +54,8 @@ const Alpine = {
         }
 
         const observer = new MutationObserver((mutations) => {
+            if (this.pauseObserver) return;
+
             for (let i=0; i < mutations.length; i++){
                 if (mutations[i].addedNodes.length > 0) {
                     mutations[i].addedNodes.forEach(node => {