Created
May 14, 2012 13:41
-
-
Save knowuh/2694043 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Mysystem2.prototype.render = function() { | |
var latestState = this.getLatestState(); | |
if (latestState !== null) { | |
/* | |
* get the response from the latest state. the response variable is | |
* just provided as an example. you may use whatever variables you | |
* would like from the state object (look at templatestate.js) | |
*/ | |
var latestResponse = latestState.response; | |
this.domIO.textContent = latestResponse; | |
} | |
// It turns out that sometimes when firebug is enabled and reloading | |
// the page and switching back to the step: The SC.onReady.done method is never called | |
// which should mean the jquery ready method is never called either. | |
// It seems this has to do with how the step iframe is setup. Its contents are injected | |
// instead of loading it from a url. So far the approach below seems to fix this problem | |
// and not cause other problems. | |
if (!SC.isReady) { | |
SC.onReady.done(); | |
} | |
var lastRenewal = 0; | |
if (typeof eventManager != 'undefined') { | |
// watch for changes to the student data and renew the session whenever it changes | |
$('#my_system_state').bind("DOMSubtreeModified", function() { | |
var now = new Date().getTime(); | |
if (now - lastRenewal > 15000) { // only renew at most once every 15 seconds | |
SC.Logger.log("renewing session"); | |
eventManager.fire('renewSession'); | |
lastRenewal = now; | |
} | |
}); | |
} | |
if (this.content) { | |
MySystem.loadWiseConfig(this.content, latestState); | |
} | |
if (latestState) { | |
MySystem.updateFromDOM(); | |
} | |
}; | |
/** | |
* This function retrieves the latest student work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am seeing about 15 or so events being triggered at once here, each with their own var context.
So my guess is that "render" is being called fresh for every "renewSession". -- in which case we don't want to call 'renewSession here' , but instead some data saving method.