Coding style
We suggest to follow the Atom guidelines.
Coding recommendations
We prefer to use the last JavaScript features because the language is evolving rapidly and offering more and more abstraction and ways to write clean and readable code. We list important points.
- Require strategy
Use require whenever it is possible to reference a module. Export the objects and functions with module exports. It is possible to avoid long paths: https://gist.github.com/branneman/8048520 - Remove var
Never use var but const and let when const is not possible (number or string variable that is modified). - Function style
Callbacks should be defined by:
- Anonymous functions (does not redefine this).
- Functions with name. In that case, add .bind(this) at the end of the function name when registering the callback.
- Class
Classes should be used.
- Define classes whenever it is possible.
- Private members have a name starting by '_' are in fact public but may not be used.
- Define getters and setters to access private members.
Single point of interaction with Nomad
A single point of interaction with Nomad is used to help minimise errors with ZeroMQ and debug the values that are used in vEXP.
The VEXPController object is created to be the point of contact with Nomad and all of the communication should be done with this object. There can only be one instance of this class at a time and the singleton design pattern was used to make sure of this.
All of the other JavaScript classes and html pages are able to use the VEXPController object in order to call methods and change the values of the planes, sample, ki, kf etc.
There are actually two implementations of VEXPController: NomadDataAcccessor and DirectDataAccessor accessing or not Nomad.
Updating 3D graphics
A publisher subscriber implementation (module pubsub-js) is used in order to update the 3D reciprocal View created with Three.js. The alternative is to add flags to the renderer however new objects should not be created in the renderer due to memory overflow issues.
It is imperative to use the publisher to send messages to the 3D view in order to add/remove/edit the objects in the scene. The implementation of pubsub-js delivers asynchronous messages.
Additional notes
- Use of tab to validate the content of a text box is not portable: check if it can be improved: current solution is not reliable (example in planes.html).