question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Separate each tool into its own file, starting with "toggleExport"

See original GitHub issue

Currently all the different tools live in this file:

https://github.com/publiclab/Leaflet.DistortableImage/blob/main/src/edit/DistortableImage.Edit.js

I think it makes sense to create a new folder such as:

/src/edit/tools/

and have each tool be a separate file like:

/src/edit/tools/export.js /src/edit/tools/showToolbar.js

etc. However, this library is not compiled using browserify or webpack and so we can’t use require() to do this.

Is it:

  1. to add the tool methods to a subobject of Leaflet, like L.DistortableImage.EditTools?
  2. to refactor this library to start using require (a lot of work… maybe not worth it)

In either case, we’ll have to pass in some context to the tools; most ask for access to this, which in this case is the L.DistortableImage.Edit context. We could pass this in like so:

L.DistortableImage.EditTools = L.DistortableImage.EditTools || {};

L.DistortableImage.EditTools.Export = function(edit) {
  function tool() {
    // then we can call it as we had been using `this`:
    // so this: this._lockHandles = new L.LayerGroup();
    // becomes:
    edit._lockHandles = new L.LayerGroup();
  }
  return tool; 
}

Then back in the original DistortableImage.Edit.js file, we’d bind it back in like this:

_toggleExport: L.DistortableImage.EditTools.Export(this);

The only thing left is that we’d need to add each tool to the concatenation script here:

https://github.com/publiclab/Leaflet.DistortableImage/blob/a3dc6d10cc98716c6106261f47a8b9cee5be3c49/Gruntfile.js#L78-L81

This is a bit convoluted but should result in a simpler set of source files for the tools, where each file represents only a single function.

@rexagod @sashadev-sky what do you think of this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sashadev-skycommented, Apr 12, 2019

@rexagod pinned!

0reactions
sashadev-skycommented, Jan 13, 2020

This one is good to close now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

csplit: A Better Way to Split File in Linux Based on its Content
Using csplit to split files in Linux. The csplit tool is a cousin of the split tool that can be used to split...
Read more >
The Org Manual - Org mode
Org Mode is an authoring tool and a TODO lists manager for GNU Emacs. It relies on a lightweight plain-text markup language used...
Read more >
Convert Column to Comma Separated List
Quickly convert a data list to CSV. Copy/paste a list from Excel to convert columns to comma-delimited values. Save settings & auto-copy results....
Read more >
The Org Manual - GNU.org
When used at the beginning of a regular line of text, turn that line into a heading. When this command is used in...
Read more >
linux - Split one file into multiple files based on delimiter
A one liner, no programming. (except the regexp etc.) csplit --digits=2 --quiet --prefix=outfile infile "/-|/+1" "{*}". tested on: csplit (GNU coreutils) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found