// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define(["dojo/_base/declare","dojo/_base/lang","dojo/topic"],function(k,e,b){var g=null;var h=k(null,{constructor:function(a){b.subscribe("publishData",e.hitch(this,this.onDataPublished));b.subscribe("fetchData",e.hitch(this,this.onFetchData));b.subscribe("clearAllData",e.hitch(this,this.onClearAllData));b.subscribe("removeData",e.hitch(this,this.onRemoveData));b.subscribe("clearDataHistory",e.hitch(this,this.onClearDataHistory));this.widgetManager=a},_dataStore:{},onDataPublished:function(a,c,d,
f){"undefined"===typeof f&&(f=!1);this._dataStore[c]?(this._dataStore[c].current=d,f&&(this._dataStore[c].history?this._dataStore[c].history.push(d):this._dataStore[c].history=[d])):(this._dataStore[c]={current:d},f&&(this._dataStore[c].history=[d]))},onFetchData:function(a){var c;if(a)"framework"===a?this._dataStore[a]?b.publish("dataFetched","framework","framework",this._dataStore[a].current,this._dataStore[a].history):b.publish("noData","framework","framework"):(c=this.widgetManager.getWidgetById(a))?
this._dataStore[a]?b.publish("dataFetched",c.name,a,this._dataStore[a].current,this._dataStore[a].history):b.publish("noData",c.name,a):b.publish("noData",void 0,a);else{for(var d in this._dataStore)(c=this.widgetManager.getWidgetById(d))&&b.publish("dataFetched",c.name,d,this._dataStore[d].current,this._dataStore[d].history);c||b.publish("noData",void 0,void 0)}},onClearAllData:function(){this._dataStore={};b.publish("allDataCleared")},onRemoveData:function(a){delete this._dataStore[a];b.publish("dataRemoved",
a)},onClearDataHistory:function(a){this._dataStore[a]&&(this._dataStore[a].history=[]);b.publish("dataHistoryCleared",a)}});h.getInstance=function(a){null===g&&(g=new h(a));return g};return h});