Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isolate all tools into separate .js files #75

Closed
8 of 27 tasks
katjaq opened this issue Oct 14, 2017 · 10 comments · Fixed by #121
Closed
8 of 27 tasks

isolate all tools into separate .js files #75

katjaq opened this issue Oct 14, 2017 · 10 comments · Fixed by #121

Comments

@katjaq
Copy link
Collaborator

katjaq commented Oct 14, 2017

What is the current behavior?

Currently, all of MicroDraw's tools functions are inside one big microdraw.js file. We would like to create one .js file for each tool. (so that in the end we could even work towards a configurable toolbar)

What is the expected or desired behaviour?

We would like to create one .js file for each tool. (so that in the end we could even work towards a configurable toolbar)

Join us! 😃 To help us, you can find details for the two extraction cases below our list of tools.

Please reply here as soon as you start working on one tool to avoid redundant effort :)

These are all the tools we want to separate:

  • navigate
  • home
  • zoomIn
  • zoomOut
  • previous
  • next
  • select
  • draw
  • drawPolygon
  • simplify
  • addPoint
  • deletePoint
  • addRegion
  • deleteRegion
  • splitRegion
  • rotate
  • flip
  • toPolygon
  • toBezier
  • copy
  • paste
  • save
  • screenshot
  • delete
  • closeMenu
  • openMenu
  • undo (is that separable? would be ideal)

To jump in helping us, have a look at the first tool separation in this pull request #74 by @r03ert0 and follow this example to separate more tools.
For all tools that simply require a click, this is the way to go:

    1. find the function you would like to separate inside public/js/microdraw.js
    1. extract the function's code from microdraw.js and add your separated tool to the /public/js/tools/yourTool.js
    1. add your tool to the Microdraw object's extension (search inside public/js/microdraw.js for
// extend Microdraw with tools
  • and add the two according lines there
    1. and change it in the switch case for your tool by finding your tool inside public/js/microdraw.js
switch(me.selectedTool) {

and you are done 😃
\ö/ thank youuuu

For all tools that require mouseDown and mouseUp handler you can follow the example in pull request #76 and see how to encapsulate tools like draw and draw polygon. This should help encapsulating some other tools. It doesn't work for tools that require the mouseDrag handler, such as rotate.

@katjaq
Copy link
Collaborator Author

katjaq commented Oct 14, 2017

i am separating the bezierToPolygon function!

@r03ert0
Copy link
Owner

r03ert0 commented Oct 14, 2017

in pull request #76 you can see how to encapsulate tools like draw and draw polygon that require a mouseDown and a mouseUp handler. This should help encapsulating some other tools. It doesn't work for tools that require the mouseDrag handler, such as rotate.

The encapsulation is not complete, and there are still references to the "draw" and "drawPolygon" tool in microdraw.js. These should be completely removed when the encapsulation will be finished.

@katjaq
Copy link
Collaborator Author

katjaq commented Oct 14, 2017

for all tools that simply require a click, this is the way to go:

  1. find the function you would like to separate inside public/js/microdraw.js

  2. extract the function's code from microdraw.js and add your separated tool to the /public/js/tools/yourTool.js

  3. add your tool to the Microdraw object's extension (search inside public/js/microdraw.js for

// extend Microdraw with tools

and add the two according lines there

  1. and change it in the switch case for your tool by finding your tool inside public/js/microdraw.js
switch(me.selectedTool) {

and you are done 😃
\ö/ thank youuuu

@geoffdavis92
Copy link

@katjaq are there any more tools that need extraction? I can't readily identify any remaining tools.

Also, is there any desire to migrate to using ES Modules and Webpack? It seems like this issue and #59 would greatly benefit from having explicitly-listed module imports/exports in each file, and would likely make debugging/adding features easier. (Take with a grain of salt, I'm just looking through the codebase, so there's likely nuances I'm missing)

@xgui3783
Copy link
Collaborator

ES module would be a godsent.

Was going to make a snarky remark about the complexity of webpack, but after some mental gymnastics, I came to the conclusion that it definitely could work.

If there are enough interest we could implement.

@geoffdavis92
Copy link

@xgui3783 cool. I'm not sure what the unique challenges are since I haven't looked at this codebase very in-depth, but wanted to offer this as an option, since that's essentially what this is asking for.

I'd be willing to help migrate these global functions towards Webpack and setup the config; I'm in no way a master but have been using it frequently on a number of side projects.

@xgui3783
Copy link
Collaborator

xgui3783 commented Oct 15, 2017 via email

@katjaq
Copy link
Collaborator Author

katjaq commented Oct 15, 2017

@geoffdavis92 : Thank you very much for your contribution! 😃
We updated the first entry in this issue to include the list of tools that exist and would ideally be extracted into their own files.
Also, it sounds great to aim at migrating these global functions towards Webpack. Once the tools are extracted, that should be easier and could be our aim? :) I agree with @xgui3783 !!! 😃

@r03ert0
Copy link
Owner

r03ert0 commented Oct 15, 2017

i'll work on splitRegion! done :D

@katjaq
Copy link
Collaborator Author

katjaq commented Oct 15, 2017

cool! :)
I'll work on select! done :D

r03ert0 pushed a commit that referenced this issue Aug 16, 2023
avoid waiting to be blocked by cors when loading a dataset in localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants