-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappState.min.js
8 lines (8 loc) · 2.39 KB
/
appState.min.js
1
2
3
4
5
6
7
8
//appState utils, StateObject and Stack
//source at: https://github.com/Vassi/appState
;(function(b){b.utils=b.utils||{};var d=function(b,c){if(c===void 0||c===null)throw new TypeError;var e=Object(c),d=e.length>>>0;if(d===0)return-1;if(0>=d)return-1;for(var a=0;a<d;a++)if(a in e&&e[a]===b)return a;return-1};b.utils.indexOf=function(b,c){return Array.prototype.indexOf?b.indexOf(c):d(c,b)};b.utils.logWarning=function(b){console!=="undefined"&&"log"in console&&console.log(b)};b.utils.registerCallback=function(d,c){if(typeof c!=="function")return b.utils.logWarning("("+parentState+"): callback not registered. Object is not a function."),
!1;d.push(c);return!0};b.utils.deregisterCallback=function(d,c){var e=b.utils.indexOf(d,c);e!==-1&&d.splice(e,1)}})(window.appState=window.appState||{});
(function(b){b.StateObject=function(d){if(typeof d!=="string"||!d)throw Error("StateObject could not be initialized because the stateName was not a string or was empty.");var g=this,c=[],e=[];this.getStateName=function(){return d};var f=function(a,b){for(var c=0;c<a.length;c++){var d=a[c];typeof d==="function"&&d(g,b)}};this.stateEnter=function(a){f(c,a)};this.stateExit=function(){f(e)};this.registerInitCallback=function(a){b.utils.registerCallback(c,a)};this.registerExitCallback=function(a){b.utils.registerCallback(e,
a)};this.deregisterInitCallback=function(a){b.utils.deregisterCallback(c,a)};this.deregisterExitCallback=function(a){b.utils.deregisterCallback(e,a)};this.clearInitCallbacks=function(){c.splice(0,c.length)};this.clearExitCallbacks=function(){e.splice(0,e.length)}}})(window.appState=window.appState||{});
(function(b,d){b.Stack=function(g,c){var e=typeof g==="function"?g:d,f=typeof c==="function"?c:d,a=[],l=this,j=function(a){if(!b.StateObject.prototype.isPrototypeOf(a))throw Error("appState.Monitor: State does not inherit from appState.StateObject.");},k=function(){return a.length>0?a[a.length-1]:d},h=function(){var a=k();a&&(f&&f(a),a.stateExit())},i=function(a){var b=k();b&&(e&&e(b,a),b.stateEnter(b,a))};this.setInitCallback=function(a){e=typeof a==="function"?a:d};this.currentState=function(){return k()};
this.pushState=function(b,c){j(b);h();a.push(b);i(c)};this.swapState=function(b,c){j(b);h();a.pop();a.push(b);i(c)};this.popState=function(){h();a.pop();i()};this.clear=function(){h();a.splice(0,a.length)};this.reset=function(b,c){j(b);l.clear();a.push(b);i(c)}}})(window.appState=window.appState||{});