Skip to content

Commit

Permalink
Move "utility functions" section to OSF page; link to style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
sloria committed Jan 19, 2015
1 parent 3c694e3 commit 742d97d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
20 changes: 20 additions & 0 deletions docs/osf/js_modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,33 @@ Javascript Modules How-To

This section describes how to write Javascript modules for the OSF, use `webpack <https://webpack.github.io/docs/>`_ to build assets, and include built assets in HTML. We also provide starter templates for new JS modules.

.. seealso::
Looking for the JS style guidelines? See :ref:`here <javascript_style>` .

Writing Modules
***************

- Use the CommonJS module style.
- Reuseable modules go in ``website/static/js/``. Name modules in ``lowerCamelCase``.
- Initialization code for a page goes in a module within ``website/static/js/pages/``. Name page modules with ``lower-dashed-case``.

A Note on Utility Functions
---------------------------

Put any reusable utility functions in ``website/static/osfHelpers.js``. **Do not pollute the global namespace.**

.. code-block:: javascript
// osfHelpers.js
var myCopaceticFunction = function() {...}
// ...
module.exports = {
// ...
myCopaceticFunction: myCopaceticFunction
};
Example
-------

Expand Down
27 changes: 7 additions & 20 deletions docs/style_guides/javascript.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
.. _javascript_style:

Javascript
==========

Style guidelines for writing Javascript.

.. seealso::
Writing a JS module for the OSF? See the :ref:`Javascript Modules <osf_js_modules>` page in the OSF section.

Style
*****

Expand Down Expand Up @@ -74,23 +81,6 @@ When using ``$.osf.postJSON``, ``$.osf.putJSON``, or ``jQuery.ajax``, use the Pr
// OR
$.ajax({ ... }).then(successHandler, failureHandler);
Utility functions
*****************

Put any reusable utility functions in ``website/static/osfHelpers.js``. **Do not pollute the global namespace.**

.. code-block:: javascript
// osfHelpers.js
var myCopaceticFunction = function() {...}
// ...
module.exports = {
// ...
myCopaceticFunction: myCopaceticFunction
};
Encapsulation
*************
Expand Down Expand Up @@ -119,9 +109,6 @@ Use the Combination Constructor/Prototype pattern for encapsulation (it's simple
module.exports = Person;
.. seealso::
Writing a JS module for the OSF? See the :ref:`Javascript Modules <osf_js_modules>` page in the OSF section.

Recommended Syntax Checkers
***************************

Expand Down

0 comments on commit 742d97d

Please sign in to comment.