diff --git a/binderhub/static/js/index.js b/binderhub/static/js/index.js index c29f0b420..3eb83ddc1 100644 --- a/binderhub/static/js/index.js +++ b/binderhub/static/js/index.js @@ -1,14 +1,4 @@ /* If this file gets over 200 lines of code long (not counting docs / comments), start using a framework - State transitions that are valid are: - start -> waiting - start -> built - start -> failed - waiting -> building - waiting -> failed - building -> pushing - building -> failed - pushing -> built - pushing -> failed */ import ClipboardJS from 'clipboard'; import 'event-source-polyfill'; @@ -54,7 +44,7 @@ function build(providerSpec, log, fitAddon, path, pathType) { const buildEndpointUrl = new URL("build", new URL(BASE_URL, window.location.href)); const image = new BinderRepository(providerSpec, buildEndpointUrl, buildToken); - image.onStateChange('*', function(oldState, newState, data) { + image.onStateChange('*', function(data) { if (data.message !== undefined) { log.writeAndStore(data.message); fitAddon.fit(); @@ -92,16 +82,14 @@ function build(providerSpec, log, fitAddon, path, pathType) { image.close(); }); - image.onStateChange('built', function(oldState) { - if (oldState === null) { - $('#phase-already-built').removeClass('hidden'); - $('#phase-launching').removeClass('hidden'); - } + image.onStateChange('built', function() { + $('#phase-already-built').removeClass('hidden'); + $('#phase-launching').removeClass('hidden'); $('#phase-launching').removeClass('hidden'); updateFavicon(BASE_URL + "favicon_success.ico"); }); - image.onStateChange('ready', function(oldState, newState, data) { + image.onStateChange('ready', function(data) { image.close(); // If data.url is an absolute URL, it'll be used. Else, it'll be interpreted // relative to current page's URL. diff --git a/js/packages/binderhub-client/lib/index.js b/js/packages/binderhub-client/lib/index.js index 4261e4a7a..fa9c66f56 100644 --- a/js/packages/binderhub-client/lib/index.js +++ b/js/packages/binderhub-client/lib/index.js @@ -33,7 +33,6 @@ export class BinderRepository { this.buildUrl.searchParams.append("build_token", buildToken); } this.callbacks = {}; - this.state = null; } /** @@ -128,39 +127,14 @@ export class BinderRepository { } } - /** - * @param {string} oldState Old state the building process was in - * @param {string} newState New state the building process is in - * @returns True if transition from oldState to newState is valid, False otherwise - */ - validateStateTransition(oldState, newState) { - if (oldState === "start") { - return ( - newState === "waiting" || newState === "built" || newState === "failed" - ); - } else if (oldState === "waiting") { - return newState === "building" || newState === "failed"; - } else if (oldState === "building") { - return newState === "pushing" || newState === "failed"; - } else if (oldState === "pushing") { - return newState === "built" || newState === "failed"; - } else { - return false; - } - } - _changeState(state, data) { [state, "*"].map(key => { const callbacks = this.callbacks[key]; if (callbacks) { for (let i = 0; i < callbacks.length; i++) { - callbacks[i](this.state, state || this.state, data); + callbacks[i](data); } } }); - - if (state && this.validateStateTransition(this.state, state)) { - this.state = state; - } } }