Electron: Dragula not functioning?

127 Views Asked by At

I've been trying to use the npm dragula in my electron application and after wrestling with the proper way to include modules into my html(which am still not sure on to be honest) I have encountered a series of errors.

My first attempt code: Html

<div id="btnContain">
      <div class="btnContain1">Button area</div>
      <div class="btnContain1">Button area</div>
      <div class="btnContain1">Button area</div>
      <div class="btnContain1">Button area</div>
      <div class="btnContain1">Button area</div>
      <div class="btnContain1">Button area</div>
      <div class="btnContain1">Button area</div>
      <div class="btnContain1">Button area</div>
      <div class="btnContain1">Button area</div>
      <div id="btnContain2"></div>
    </div>
    </div>
<!-- i have this many because I needed the div to scroll -->

javascript

require('dragula')
      function dragula () {
      dragula([document.getElementById('btnContain2'), document.getElementById('btnContain')]);
      }

I have put the dragula into a function because without it, it returns the dragula is not defined error then I ran that code without any errors but it wasn't functional. So I noticed that i have to call the function which I did.

require('dragula')
      function dragula () {
      dragula([document.getElementById('btnContain2'), document.getElementById('btnContain')]);
      }
      dragula()

But this returns the Maximum call stack size exceeded error which is because the dragula keeps on repeatedly calling it self over and over.

At this point am unsure what to do and my 17 days of javascript has unsurprisingly failed me. Any tips on this issue will be very much appreciated as well as tips going forward.

(Please have mercy on me if I've done something stupid)

Edit: I've read through this post on how to solve the stack size error but not sure how to make a case to meet in my scenario.

1

There are 1 best solutions below

1
On BEST ANSWER

I managed to fix it with the code below

var dragula = require('dragula')
      dragula([document.getElementById('btnContain2'), document.getElementById('btnContain')]);

Good luck to everyone else having this issue in the future!