Skip to content

Instantly share code, notes, and snippets.

@knowuh
Created May 14, 2012 13:41
Show Gist options
  • Save knowuh/2694043 to your computer and use it in GitHub Desktop.
Save knowuh/2694043 to your computer and use it in GitHub Desktop.
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
@knowuh
Copy link
Author

knowuh commented May 14, 2012

line 30 is triggering a renewsession event, because the 'student' data in #my_system_state is being modified.
Its actually not being modified. We could do a simple compare on the text value before triggering the event.

@knowuh
Copy link
Author

knowuh commented May 14, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment