Created
December 28, 2010 17:43
-
-
Save JamieMason/757462 to your computer and use it in GitHub Desktop.
Note to self for the format of modules in JamieMVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var simpleData = function (data) | |
{ | |
var that = {}; | |
// Decorators should always hold a simpleData instance, as you can nest instances | |
// we do checking here rather than in every decorator | |
if (typeof data.set === 'function') | |
{ | |
return data; | |
} | |
// PRIVATE METHODS | |
// ################################################ | |
// PUBLIC | |
// ################################################ | |
that.set = function(candidate) | |
{ | |
data = candidate; | |
// if changed etc here... | |
$(that).trigger('change'); | |
} | |
that.get = function() | |
{ | |
return data; | |
} | |
// INIT | |
// ################################################ | |
return that; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sortableData = function (data) | |
{ | |
var that = {}, | |
_super, | |
_data; | |
// PRIVATE METHODS | |
// ################################################ | |
function _onChange(newData) | |
{ | |
_data = newData + ' sorted'; | |
return _data; | |
} | |
// PUBLIC | |
// ################################################ | |
that.set = function(x) | |
{ | |
// set our simpleData, if it changes our onChange will finish it off | |
_super.set(x); | |
} | |
that.get = function() | |
{ | |
return _data; | |
} | |
// INIT | |
// ################################################ | |
// always keep a simpleData instance | |
_super = simpleData(data); | |
// when the simpleData instance changes we process it and store it | |
_data = _onChange(_super.get()); | |
// re-process our data whenever the simpleData instance changes | |
$(_super).bind('change', function() | |
{ | |
_onChange(_super.get()); | |
}); | |
return that; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment