I came across an interesting challenge, I have the following code:
Sm.screenfragment(function (screen, viewModel) {
//This can grow very quickly and turn into a mess
var attribA = screen.get('title'),
...
...
attribZ = screen.get('status');
var setAttribA = function (container) {
//Do Stuff
};
...
...
var setAttribZ = function(event, viewName) {
//Do Stuff
};
//So this can grow hundreads of lines and get messy.
return {
model: {
//Do Stuff
},
create: function () {
//Do Stuff
},
prepare: function (callback, config) {
//Do Stuff
},
enter: function () {
//Do Stuff
},
exit: function (callback) {
//Do Stuff
}
};
});
I have tried a few ideas, but they are little more than messing with the syntax:
I thought about adding a new util object, I can construct util objects, so it just adds a little structure, but not much more.
Sm.screenfragment(function (screen, viewModel) {
//Still can grow into a mess
var util = {
attribA : screen.get('title'),
attribB : screen.get('status'),
setAttribA : function (container) {
//Do Stuff
},
setAttribB : function(event, viewName) {
//Do Stuff
}
};
return {
model: {
//Do Stuff
},
create: function () {
//Do Stuff
util.setAttribA...
},
prepare: function (callback, config) {
//Do Stuff
},
enter: function () {
//Do Stuff
},
exit: function (callback) {
//Do Stuff
}
};
});
Then use dot notation to get the attributes, but this does not make the mess go away. I am re-reading stuff on the Module Pattern to see if I can apply something here, I have extreme cases where I can have dozens of proprieties and functions on the top of the file, and it just breaks the structure. How can I arrange the code in a more modular way? So that it does not get cluttered.
main.jsandutil.js?