Last active
August 29, 2015 14:17
-
-
Save gundisalwa/84f294b2b34f6bea2db5 to your computer and use it in GitHub Desktop.
Mock for a CDE dashboard watcher
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
function isEditorActive(){ | |
return document.hasFocus(); | |
} | |
function getActiveDashboardStateId (){ | |
// Returns an identifier for the current saved state of the dashboard. | |
} | |
function getSavedDashboardStateId( ){ | |
return $.ajax('dashboard_state_endpoint_url'); | |
} | |
function promptReload(){ | |
// Prompts the user to reload the dashboard | |
} | |
function throttle(){ | |
// Some throttle implementation. Underscore.js has one. | |
} | |
var throttledTest = throttle( function ( callback ){ | |
return getSavedDashboardStateId(); | |
}, 1000 ); | |
function handleSavedStateResponse ( newSavedStateId ){ | |
if ( newSavedStateId !== getActiveDashboardStateId() ){ | |
promptReload(); | |
} else if ( !isEditorActive() ){ | |
throttledTest( ).then( handleSavedStateResponse ); | |
} | |
} | |
function startSavedStateTest(){ | |
throttledTest( ).then( handleSavedStateResponse ); | |
} | |
//---------------------------------------// | |
$(window).blur( startSavedStateTest ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment