{"version":3,"file":"loan_controller-fjRPSAdi.js","sources":["../../app/assets/javascript/controllers/channels/loan_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\"\nimport consumer from \"../../channels/consumer\"\n\nexport default class extends Controller {\n static values = {\n id: String,\n payload: Object,\n };\n\n receivedMessage({ meta, payload }) {\n if (meta.force_refresh) {\n this.processRefresh(payload);\n return;\n }\n\n for (const key in this.payloadValue) {\n if (this.payloadValue[key] !== payload[key]) {\n this.processRefresh(payload);\n return;\n }\n }\n }\n\n processRefresh(payload) {\n this.payloadValue = payload;\n\n if (this.refreshTimeout) {\n clearTimeout(this.refreshTimeout);\n }\n\n // Delay redirect by a few seconds to avoid race conditions\n // with async jobs that run after the changes that triggered a broadcast\n this.refreshTimeout = setTimeout(() => {\n Turbo.visit(window.location.href, { action: \"replace\" });\n }, 2500);\n }\n\n connect() {\n this.channel = consumer.subscriptions.create(\n { channel: \"LoanChannel\", loan_id: this.idValue },\n { received: (data) => this.receivedMessage(data) }\n );\n }\n\n disconnect() {\n this.channel.unsubscribe();\n\n clearTimeout(this.refreshTimeout);\n }\n}\n"],"names":["loan_controller","Controller","meta","payload","key","consumer","data","__publicField"],"mappings":"6UAGe,MAAKA,UAASC,CAAW,CAMtC,gBAAgB,CAAE,KAAAC,EAAM,QAAAC,GAAW,CACjC,GAAID,EAAK,cAAe,CACtB,KAAK,eAAeC,CAAO,EAC3B,MACN,CAEI,UAAWC,KAAO,KAAK,aACrB,GAAI,KAAK,aAAaA,CAAG,IAAMD,EAAQC,CAAG,EAAG,CAC3C,KAAK,eAAeD,CAAO,EAC3B,MACR,CAEA,CAEE,eAAeA,EAAS,CACtB,KAAK,aAAeA,EAEhB,KAAK,gBACP,aAAa,KAAK,cAAc,EAKlC,KAAK,eAAiB,WAAW,IAAM,CACrC,MAAM,MAAM,OAAO,SAAS,KAAM,CAAE,OAAQ,UAAW,CACxD,EAAE,IAAI,CACX,CAEE,SAAU,CACR,KAAK,QAAUE,EAAS,cAAc,OACpC,CAAE,QAAS,cAAe,QAAS,KAAK,OAAS,EACjD,CAAE,SAAWC,GAAS,KAAK,gBAAgBA,CAAI,CAAC,CACjD,CACL,CAEE,YAAa,CACX,KAAK,QAAQ,YAAa,EAE1B,aAAa,KAAK,cAAc,CACpC,CACA,CA7CEC,EADkBP,EACX,SAAS,CACd,GAAI,OACJ,QAAS,MACV"}