text: (this["webpackJsonpdurable-mvc-starter-ui"]=this["webpackJsonpdurable-mvc-starter-ui"]||[]).push([[0],{32:function(t,e,n){},38:function(t,e,n){"use strict";n.r(e);var i=n(1),a=n.n(i),s=n(13),o=n.n(s),r=(n(32),n(8)),c=n(11),l=n(15),y=n(14),u=n(26),h=n(27),f=n(2),g=n(6),d=n(16),v=function(){function t(){Object(r.a)(this,t),this.entityName="",this.entityKey="",this.version=0,this.stateDiff=[],this.isEntityDestructed=!1}return Object(c.a)(t,null,[{key:"GetEntityId",value:function(e){return t.FormatEntityId(e.entityName,e.entityKey)}},{key:"FormatEntityId",value:function(t,e){return"@".concat(t,"@").concat(e)}}]),t}(),E=n(17),S=n(9),m="/a/p/i",p=function(t){Object(l.a)(n,t);var e=Object(y.a)(n);function n(t){var i;return Object(r.a)(this,n),(i=e.call(this,g.d.instance))._configFabric=t,i}return Object(c.a)(n,[{key:"send",value:function(t){var e=this;if(t.url.includes(m)){var i=this._configFabric();if(i.accessTokenFactory)return i.accessTokenFactory().then((function(i){return t.headers={},t.headers.Authorization="Bearer "+i,Object(E.a)(Object(S.a)(n.prototype),"send",e).call(e,t)}));if(i.fakeUserNamePromise)return i.fakeUserNamePromise.then((function(i){return i&&(t.headers={},t.headers["x-ms-client-principal-name"]=i),Object(E.a)(Object(S.a)(n.prototype),"send",e).call(e,t)}))}return Object(E.a)(Object(S.a)(n.prototype),"send",this).call(this,t)}}]),n}(g.a),b=function(){function t(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];Object(r.a)(this,t),this._entityName=e,this.items=[],this._entityName=this._entityName.toLowerCase(),Object(f.m)(this,{items:f.n}),n&&this.attachAllEntities()}return Object(c.a)(t,[{key:"attachAllEntities",value:function(){t.initSignalR(),t.EntitySets[this._entityName]=this.items,t.fetchAndApplyAllEntityStates(this._entityName)}},{key:"attachEntity",value:function(e){var n=v.FormatEntityId(this._entityName,e);t.EntityStates[n]||(t.EntitySets[n]=this.items,t.attachEntity(this._entityName,e,void 0))}},{key:"createEntity",value:function(e){t.createEntity(this._entityName,e,void 0)}},{key:"signalEntity",value:function(e,n,i){return t.signalEntity(this._entityName,e,n,i)}},{key:"callEntity",value:function(e,n,i){return t.callEntity(this._entityName,e,n,i)}},{key:"updateEntityMetadata",value:function(e,n){return t.updateEntityMetadata(this._entityName,e,n)}}],[{key:"attachEntity",value:function(e,n,i){t.initSignalR(),e=e.toLowerCase();var a=v.FormatEntityId(e,n);return this.EntityStates[a]?this.EntityStates[a].state:(i&&Object(f.l)(i),this.fetchAndApplyEntityState(e,n,0,0,i),i)}},{key:"createEntity",value:function(t,e,n){return this.updateEntityMetadata(t,e,{}),this.attachEntity(t,e,n)}},{key:"signalEntity",value:function(t,e,n,i){t=t.toLowerCase();var a="".concat(m,"/entities/").concat(t,"/").concat(e,"/").concat(n);return this.HttpClient.post(a,{content:JSON.stringify(i)}).then()}},{key:"callEntity",value:function(t,e,n,i){var a=this;t=t.toLowerCase();var s="".concat(m,"/entities/").concat(t,"/").concat(e,"/").concat(n);return new Promise((function(t,e){a.HttpClient.post(s,{content:JSON.stringify(i)}).then((function(n){var i=JSON.parse(n.content).correlationId;a.SignalResultPromises[i]={resolve:t,reject:e}}),e)}))}},{key:"updateEntityMetadata",value:function(t,e,n){return this.signalEntity(t,e,"$update-entity-internal-metadata",n)}},{key:"setup",value:function(t){this.Config=t,this.Config.logger||(this.Config.logger=g.d.instance)}},{key:"entityAdded",value:function(t,e,n){var i=v.FormatEntityId(t,e),a=this.EntitySets[i];a?delete this.EntitySets[i]:a=this.EntitySets[t],a&&(n.entityKey=e,a.push(n))}},{key:"entityDeleted",value:function(t,e){var n=this.EntitySets[t];if(n)for(var i=0;i<n.length;i++)if(n[i].entityKey===e){n.splice(i,1);break}}},{key:"fetchAndApplyEntityState",value:function(t,e,n,i){var a=this,s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,o="".concat(m,"/entities/").concat(t,"/").concat(e);this.HttpClient.get(o).then((function(i){var o=JSON.parse(i.content),r=v.FormatEntityId(t,e);if(n&&o.version<n)throw new Error("Expected ".concat(r," of version ").concat(n,", but got version ").concat(o.version));if(s){o.state.entityKey=s.entityKey;var c=d.createPatch(s,o.state);d.applyPatch(s,c)}else s=o.state,Object(f.l)(s);a.EntityStates[r]||a.entityAdded(t,e,s),a.EntityStates[r]={state:s,version:o.version}})).catch((function(o){i<a.MaxRetryCount?(i++,setTimeout((function(){a.fetchAndApplyEntityState(t,e,n,i,s)}),i*a.RetryBaseIntervalMs)):a.Config.logger.log(g.c.Error,"DurableEntitySet: failed to fetch entity state: ".concat(o))}))}},{key:"fetchAndApplyAllEntityStates",value:function(t){var e=this,n="".concat(m,"/entities/").concat(t);this.HttpClient.get(n).then((function(n){var i,a=Object(h.a)(JSON.parse(n.content));try{for(a.s();!(i=a.n()).done;){var s=i.value,o=s.entityKey,r=v.FormatEntityId(t,o),c=s;Object(f.l)(c.state),e.EntityStates[r]=c,e.entityAdded(t,o,c.state)}}catch(l){a.e(l)}finally{a.f()}})).catch((function(t){e.Config.logger.log(g.c.Error,"DurableEntitySet: failed to fetch entity states: ".concat(t))}))}},{key:"entityStateChangedMessageHandler",value:function(t){var e=this,n=v.GetEntityId(t);if(this.Config.logger.log(g.c.Trace,"DurableEntitySet: ".concat(n," changed to version ").concat(t.version)),t.isEntityDestructed)delete this.EntityStates[n],this.entityDeleted(t.entityName,t.entityKey);else if(this.EntityStates[n]){var i=this.EntityStates[n].version+1;t.version>i?this.fetchAndApplyEntityState(t.entityName,t.entityKey,t.version,0,this.EntityStates[n].state):t.version===i&&(d.applyPatch(this.EntityStates[n].state,t.stateDiff),this.EntityStates[n].version=t.version)}else(this.EntitySets[n]||this.EntitySets[t.entityName])&&setTimeout((function(){return e.fetchAndApplyEntityState(t.entityName,t.entityKey,t.version,0)}),this.RetryBaseIntervalMs)}},{key:"entitySignalResponseHandler",value:function(t){var e=this.SignalResultPromises[t.correlationId];e&&(t.errorMessage?e.reject(new Error(t.errorMessage)):e.resolve(t.result),delete this.SignalResultPromises[t.correlationId])}},{key:"initSignalR",value:function(){var t=this;this.SignalRConn||(this.SignalRConn=(new g.b).withUrl("".concat(m),{httpClient:this.HttpClient,logger:this.Config.logger}).build(),this.SignalRConn.on("entity-state-changed",(function(e){return t.entityStateChangedMessageHandler(e)})),this.SignalRConn.on("entity-signal-response",(function(e){return t.entitySignalResponseHandler(e)})),this.SignalRConn.onclose((function(){!function e(){t.Config.logger.log(g.c.Information,"DurableEntitySet: reconnecting to SignalR..."),t.SignalRConn.start().then((function(){t.Config.logger.log(g.c.Information,"DurableEntitySet: reconnected to SignalR")}),(function(){setTimeout(e,t.SignalRReconnectIntervalInMs)}))}()})),this.SignalRConn.start().then((function(){t.Config.logger.log(g.c.Information,"DurableEntitySet: successfully connected to SignalR")}),(function(e){t.Config.logger.log(g.c.Error,"DurableEntitySet: failed to connect to SignalR: ".concat(e))})))}}]),t}();b.Config={logger:g.d.instance},b.HttpClient=new p((function(){return b.Config})),b.EntitySets={},b.EntityStates={},b.SignalResultPromises={},b.SignalRConn=void 0,b.SignalRReconnectIntervalInMs=5e3,b.MaxRetryCount=6,b.RetryBaseIntervalMs=500;var j=n(5);b.setup({fakeUserNamePromise:Promise.resolve("test-anonymous-user"),logger:{log:function(t,e){return console.log(e)}}});var C="CounterEntity",O="my-counter",k=b.createEntity(C,O,new function t(){Object(r.a)(this,t),this.title="",this.countContainer={count:0},this.history=[]}),R=Object(u.a)(function(t){Object(l.a)(n,t);var e=Object(y.a)(n);function n(){return Object(r.a)(this,n),e.apply(this,arguments)}return Object(c.a)(n,[{key:"render",value:function(){var t;return Object(j.jsxs)(j.Fragment,{children:[Object(j.jsxs)("div",{className:"counter-div",children:[Object(j.jsxs)("h3",{children:[" Title: '",k.title,"', count: ",null===(t=k.countContainer)||void 0===t?void 0:t.count]}),Object(j.jsx)("button",{onClick:function(){return b.signalEntity(C,O,"add",1)},children:"Increment"}),Object(j.jsx)("button",{onClick:function(){return b.signalEntity(C,O,"substract",1)},children:"Decrement"})]}),Object(j.jsx)("h4",{children:k.history.length?"History (last 10 values):":""}),Object(j.jsx)("ul",{children:k.history.map((function(t){return Object(j.jsx)("li",{children:t})}))})]})}}]),n}(a.a.Component));o.a.render(Object(j.jsx)(R,{}),document.getElementById("root"))}},[[38,1,2]]]);
  //# sourceMappingURL=main.1ec98c0b.chunk.js.map