uxebu/bonsai

Remove global pollution of bonsai

Opened this issue · 4 comments

currently bonsai's (worker and/or iframe) context is polluted with all bonsai classes, such as Shape, Movie, etc. imho this is a possible trap for users that start working in that context too. The first use case, we stumbled over, was plugins, that do also write into that namespace. If the use of that context grows, which would make sense, since workload is "threaded" this way, this will become a problem, jquery-plugins like :).

Here is a suggestion how to fix that:

  1. in the next version (lets say 0.5)
  • remove all global's
  • provide a function such as bonsai.makeAllGlobal(), which allows in a one liner to "fix" existing code after an upgrade to 0.5
  • mark global usage as deprectated
  1. in version 0.6 remove the function makeAllGlobal() completely, to become clean.
    alternatively it can be provided as a plugin, which should never be recommended, but would still exist, but never be part of "official" bonsai

Will this mean that we can't do things like this anymore:

new Shape()

and it would become

new bonsai.Shape()

?

exactly

I would have a small tear in my eye because we'll loose some of the ease of use of the api but just the amount of times I hit confusion when building a small demo doing stuff like following should be reason enough to require lightweight namespaces :)

var circle = new Circle() // and now what, you'll start confusing bonsai api with your own code very soon

the above is a good example. in simple scripts one might oversee where things come from.
the pollution of the "global" should make it better for future issues and real bug finding