Skip to content

Instantly share code, notes, and snippets.

@anthonychung
Created May 14, 2013 01:20
Show Gist options
  • Save anthonychung/5572908 to your computer and use it in GitHub Desktop.
Save anthonychung/5572908 to your computer and use it in GitHub Desktop.
Offending code caches function in a variable so the TextField.value never update the model.
updateUserModel = function(){
// this is bad because it caches the function in the variable,
// so the Textfield.value won't get the latest value
// but only the original cached.
// This bad practice can happen if being lazy after getting rid of the exports prefix of a commonjs exports.functionname.
// it will still work for most cases but cause nasty caching bugs for when textfield values need to be updated
var currentUser ={
firstname: $.firstName.value, // these are textfields
surname: $.surname.value,
address1: $.address1.value,
address2: $.address2.value,
suburb: $.suburb.value,
state: $.state.text,
pc: $.postCode.value,
email: $.email.value
}
Alloy.Globals.ModelUser.save(currentUser);
Alloy.Globals.ModelUser.trigger('change');
}
// # Solution
// function updateUserModel(){ }
// needs to have the traditional function.
// rather than
// updateUserModel = function(){ }
// and then later use
// exports.updateUserModel = updateUserModel;
// if we need to expose it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment