1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/technical-features/messaging/computed-channel/dist/index.js
Gabriel 6404993432 packages/ui-components/tooltip
Signed-off-by: Gabriel <gaccettola@mirantis.com>
2023-04-12 11:00:36 +02:00

1 line
1.8 KiB
JavaScript

(()=>{"use strict";var e={d:(n,t)=>{for(var o in t)e.o(t,o)&&!e.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:t[o]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};e.r(n),e.d(n,{computedChannelInjectionToken:()=>a,computedChannelObserverInjectionToken:()=>i});const t=require("@ogre-tools/injectable"),o=require("mobx"),c=require("@k8slens/messaging"),r=(0,c.getMessageChannel)("computed-channel-administration-channel"),a=((0,c.getMessageChannelListenerInjectable)({id:"computed-channel-administration",channel:r,getHandler:e=>{const n=e.inject(c.sendMessageToChannelInjectionToken),t=new Map;return c=>{if("became-observed"===c.status){const r=e.injectMany(i).find((e=>e.channel.id===c.channelId));if(void 0===r)return;const a=(0,o.reaction)((()=>r.observer.get()),(e=>n({id:c.channelId},e)),{fireImmediately:!0});t.set(c.channelId,a)}else{const e=t.get(c.channelId);null==e||e()}}}}),(0,t.getInjectionToken)({id:"computed-channel-injection-token"})),i=(0,t.getInjectionToken)({id:"computed-channel-observer"});(0,t.getInjectable)({id:"computed-channel",instantiate:e=>{const n=e.inject(c.sendMessageToChannelInjectionToken);return(t,a)=>{const i=o.observable.box(a),s=(0,o.computed)((()=>i.get())),d=(0,c.getMessageChannelListenerInjectable)({id:`computed-channel-value-receiver-for-${t.id}`,channel:t,getHandler:()=>e=>{(0,o.runInAction)((()=>{i.set(e)}))}});return(0,o.runInAction)((()=>{e.register(d)})),(0,o.onBecomeObserved)(s,(()=>{(0,o.runInAction)((()=>{i.set(a)})),n(r,{channelId:t.id,status:"became-observed"})})),(0,o.onBecomeUnobserved)(s,(()=>{(0,o.runInAction)((()=>{i.set(a)})),n(r,{channelId:t.id,status:"became-unobserved"})})),s}},injectionToken:a}),module.exports=n})();