8000 Consider how best to do global vars · Issue #297 · nudibranchrecords/hedron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Consider how best to do global vars #297

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

Closed
funwithtriangles opened this issue Sep 19, 2019 · 1 comment · Fixed by #311
Closed

Consider how best to do global vars #297

funwithtriangles opened this issue Sep 19, 2019 · 1 comment · Fixed by #311
Labels
discussion An issue that may need some discussion
Milestone

Comments

@funwithtriangles
Copy link
Member

Global vars seem to be the most convenient way to expose useful things to sketch authors. At the moment, we have THREE, POSTPROCESSING and GLSLIFY.

I'm also considering adding TWEEN for tween.js functionality. Eventually we might also want HEDRON for hedron specific utils (such as a Sketch class that can be extended, if we need to do this one day).

I'm slightly concerned we're really polluting the global namespace with all of the above and it gets hard to know what is available to a developer.

One simple approach would be to only expose one global var, HEDRON, and attach everything to that.

const { THREE, POSTPROCESSING, TWEEN, GLSLIFY, Sketch  } = HEDRON

Pros:

  • Less namespace pollution, just one global var to avoid
  • Easily console loggable by devs to see what's actually in there

Cons:

  • One more line of code to write in order to access the variables
  • Might be harder to set VSCode intellisense to recognise global var if its in an object?
@funwithtriangles funwithtriangles added the discussion An issue that may need some discussion label Sep 19, 2019
@funwithtriangles funwithtriangles added this to the 0.6.0 milestone Sep 19, 2019
@funwithtriangles
Copy link
Member Author
funwithtriangles commented Oct 9, 2019

This is now implemented on the postprocessing branch. Going for a slightly deeper structure.

window.HEDRON = {
  dependencies: {
    THREE: {
      ...THREE,
      // For convenience, also requiring some common three extras
      GLTFLoader,
      OrbitControls,
    },
    TWEEN,
    postprocessing,
    glslify,
  },
}

Used in a sketch like this:

const { THREE } = window.HEDRON.dependencies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion An issue that may need some discussion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant
0