Created
May 14, 2013 01:20
-
-
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.
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
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