var __decorate=(this&&this.__decorate)||function(decorators,target,key,desc){var c=arguments.length,r=c<3?target:desc===null?desc=Object.getOwnPropertyDescriptor(target,key):desc,d;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)if(d=decorators[i])r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r;return c>3&&r&&Object.defineProperty(target,key,r),r;};define(["require","exports","react","@core/declareDecorator","dojo/Evented","immutable","dojo/on","@core/emitter","@core/utils"],function(require,exports,React,declareDecorator_1,Evented,immutable_1,on,emitter_1,utils_1){Object.defineProperty(exports,"__esModule",{value:true});var State=(function(){function State(global_key,api_controller){var _this=this;this._handles=[];this.UPDATE_RUN_STATE="update-run-state";this.API_UPDATE_ERROR="api-update-error";if(!window[global_key]){window[global_key]={};} this._store=window[global_key];if(!window[global_key+"-emitter"]){window[global_key+"-emitter"]=new emitter_1.default();} this._errors={};this._emitter=window[global_key+"-emitter"];this._api_controller=api_controller;this.api=this._api_controller.api;this._retrieved_paths=[];this._path_meta={};this._active_actions={read:[]};this._handles.push(on(this._emitter,"update",function(data){_this.emit(data.path,data.data);}),on(this._emitter,"api-update-error",function(data){_this.emit(_this.API_UPDATE_ERROR+":"+data.path,data.data);}),on(this._emitter,this.UPDATE_RUN_STATE,function(data){_this.emit(_this.UPDATE_RUN_STATE,data);}),on(this._emitter,"read",function(data){_this.emit("READ:"+data.path,data.value);}));if(!window[global_key+"-history"]){window[global_key+"-history"]={};} if(!window[global_key+"-history-map"]){window[global_key+"-history-map"]={};} this._history=window[global_key+"-history"];this._history_map=window[global_key+"-history"];} State.prototype.viewAt=function(path){var resp=null;this.getAt(path,function(result){resp=result;},null,null,null,true);return resp;};State.prototype.getAt=function(path,callback,api,error_callback,args,skip_registered_action){var _this=this;var npath=this.normalizePath(path);this._traverse(this._store,npath,function(property_getter,property_setter){var update=function(data_object){if(data_object.error){alert("error reading from API");return;} if(Array.isArray(data_object.data)){var obj_1={};data_object.data.forEach(function(item){var id;if(Array.isArray(data_object.id_property)){id=data_object.id_property.map(function(k){return item[k];}).join("-");} else{id=item[(data_object.id_property||"id")];} obj_1[(Number.isInteger(id))?"_@"+id:id]=immutable_1.Map(item);});property_setter(obj_1);} else{property_setter(immutable_1.Map(data_object.data));} _this._retrieved_paths.push(npath);_this._path_meta[npath]={path:npath,version:(new Date()).getTime()};_this._active_actions["read"]=_this._active_actions["read"].filter(function(v){return v!==npath;});callback(property_getter());_this._emitter.emit("read",{path:npath,value:property_getter()});};if(property_getter().size===0){var use_callback=true;if(_this._api_controller&&!skip_registered_action){if(_this._api_controller.hasAction('read',npath)){if(_this._active_actions["read"].indexOf(npath)>-1){setTimeout(function(){_this.getAt(npath,callback,api,error_callback,args);},100);return;} _this._active_actions["read"].push(npath);_this._api_controller.performAction("read",npath,update,args,function(){var args=[];for(var _i=0;_i