{"version":3,"file":"toolbox-rxjs.mjs","sources":["../../../projects/toolbox/rxjs/share-and-cache.ts","../../../projects/toolbox/rxjs/keep-fresh.ts","../../../projects/toolbox/rxjs/toolbox-rxjs.ts"],"sourcesContent":["import { Observable } from \"rxjs\";\r\nimport { shareReplay, startWith, tap } from \"rxjs/operators\";\r\n\r\n/**\r\n * Stores every emitted value in localStorage, starts with the stored value if\r\n * one exists, and shares the replay of all of this.\r\n * @param cacheKey Key used in localStorage\r\n */\r\nexport const tbxShareAndCache = ( cacheKey: string ) => <T>( source: Observable<T> ) =>\r\n{\r\n  let cachedValue: T | null;\r\n\r\n  try\r\n  {\r\n    cachedValue = JSON.parse( localStorage[cacheKey] );\r\n  }\r\n  catch( parseException )\r\n  {\r\n    cachedValue = null;\r\n  }\r\n\r\n  // Cache future values\r\n  let result = source.pipe(\r\n    tap( next => ( localStorage[cacheKey] = JSON.stringify( next ) ) )\r\n  );\r\n\r\n  if( cachedValue !== null )\r\n  {\r\n    result = result.pipe( startWith( cachedValue ) );\r\n  }\r\n\r\n  return result.pipe( shareReplay( 1 ) );\r\n};\r\n","import { Observable, timer } from \"rxjs\";\r\nimport { exhaustMap } from \"rxjs/operators\";\r\n\r\n/**\r\n * Repeats underlying observable on a timer.\r\n * @param interval Number of milliseconds to wait for refresh.\r\n * @param delay Number of milliseconds to wait before emitting the first value.\r\n */\r\nexport const tbxKeepFresh = ( interval: number, delay = 0 ) =>\r\n  <T>( source: Observable<T> ) =>\r\n    timer( delay, interval ).pipe( exhaustMap( () => source ) );\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAGA;;;;AAIG;AACI,MAAM,gBAAgB,GAAG,CAAE,QAAgB,KAAM,CAAK,MAAqB,KAAK;AAErF,IAAA,IAAI,WAAqB;AAEzB,IAAA,IACA;QACE,WAAW,GAAG,IAAI,CAAC,KAAK,CAAE,YAAY,CAAC,QAAQ,CAAC,CAAE;;IAEpD,OAAO,cAAc,EACrB;QACE,WAAW,GAAG,IAAI;;;IAIpB,IAAI,MAAM,GAAG,MAAM,CAAC,IAAI,CACtB,GAAG,CAAE,IAAI,KAAM,YAAY,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,SAAS,CAAE,IAAI,CAAE,CAAE,CAAE,CACnE;AAED,IAAA,IAAI,WAAW,KAAK,IAAI,EACxB;QACE,MAAM,GAAG,MAAM,CAAC,IAAI,CAAE,SAAS,CAAE,WAAW,CAAE,CAAE;;IAGlD,OAAO,MAAM,CAAC,IAAI,CAAE,WAAW,CAAE,CAAC,CAAE,CAAE;AACxC;;AC7BA;;;;AAIG;AACI,MAAM,YAAY,GAAG,CAAE,QAAgB,EAAE,KAAK,GAAG,CAAC,KACvD,CAAK,MAAqB,KACxB,KAAK,CAAE,KAAK,EAAE,QAAQ,CAAE,CAAC,IAAI,CAAE,UAAU,CAAE,MAAM,MAAM,CAAE;;ACV7D;;AAEG;;;;"}