UNPKG

@leancodepl/hook-pipe-client

Version:

React hooks for real-time data streaming and subscriptions using @leancodepl/pipe

2 lines (1 loc) 888 B
(function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react"),require("deep-equal"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","react","deep-equal","rxjs"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e["@leancodepl/hook-pipe-client"]={},e.react,e.deepEqual,e.rxjs))})(this,(function(e,t,l,a){"use strict";function m({pipe:i}){return{createTopic(c){function s(r,{onData:o,...f}){const[q,b]=t.useState(),p=t.useRef(o),d=t.useRef(f);p.current=o,d.current=f;const n=t.useRef(null);return(n.current===null||!l(n.current,r))&&(n.current=r),t.useEffect(()=>{const h=i.topic(c,n.current).pipe(a.share()).subscribe(u=>{b(u),p.current?.(u);const[j,x]=u;d.current[j]?.(x)});return()=>h.unsubscribe()},[n.current]),{data:q}}return s.topic=r=>i.topic(c,r),s}}}e.mkPipeClient=m,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));