Skip to content

Instantly share code, notes, and snippets.

@reedling78
Created May 15, 2014 14:35
Show Gist options
  • Save reedling78/a1fc428c2e2e11d49bc9 to your computer and use it in GitHub Desktop.
Save reedling78/a1fc428c2e2e11d49bc9 to your computer and use it in GitHub Desktop.
Weld Module
define(
['services/jquery'],
function ($) {
return {
creator: function (sandbox) {
var $sandboxOption1 = $(sandbox.getOption('optionOne')),
$sandboxOption2 = $(sandbox.getOption('optionTwo')),
$sandboxOption3 = $(sandbox.getOption('optionThree'));
var nameSpace = {
init: function () {
// Perform initialization activities
// for example: maybe you need to grab a few selectors
// and assign to a variable before calling the next function
// and pass that variable as a parameter. This is a good
// example of initialization activities. init method is
// also an appropriate place to bind your on load event
// handlers such as on "click" events.
sandboxOption1.on('click', function () {
nameSpace.handleClickEvent(e);
});
nameSpace.majorFunctionality();
},
majorFunctionality: function () {
// each function should handle one part of the logic
// minor functionality such as pre-formating a string
// for use in another function should be split into
// private functions outside the namespace
var formattedString = formatString(sanbox.getOption('queryString'));
// Notice in the function call above that I placed the
// sanbox.getOption right in the code. If a sandbox option
// is only being used once, then there is no need to create a
// a global variable at the top for it. Just pull it in when
// you need it and reduce the scope of that variable.
},
handleClickEvent: function (event) {
event.preventDefault();
// perform action
}
};
function formatString(string) {
// perform action on parameter and return value
return string;
}
return {
create: function () {
nameSpace.init();
},
destroy: function () {
}
};
}
};
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment