UNPKG

1.88 kBSource Map (JSON)View Raw
1{"version":3,"file":"rx-async-policy.js","sourceRoot":"","sources":["../src/rx-async-policy.ts"],"names":[],"mappings":";;AAAA,6BAAsC;AACtC,4CAAoD;AAEpD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,MAAM,CAAC,cAAqC;IAC1D,IAAI,CAAC,CAAC,cAAc,YAAY,iBAAU,CAAC,EAAE;QAC3C,cAAc,GAAG,SAAE,CAAC,cAAc,CAAC,CAAC;KACrC;IAED,IAAM,KAAK,GAAoB,cAAc,CAAC,IAAI,CAAC,uBAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAEnE,OAAO,KAAK;SACT,IAAI,CAAC,iBAAK,EAAE,CAAC;SACb,SAAS,EAAE;SACX,IAAI,CAAC;QACJ,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACP,CAAC;AAbD,wBAaC","sourcesContent":["import { Observable, of } from 'rxjs';\r\nimport { first, shareReplay } from 'rxjs/operators';\r\n\r\n/**\r\n * Determines the unwrapping behavior of asynchronous resolve values.\r\n *\r\n * - When an Observable is returned from the resolveFn, wait until the Observable emits at least one item.\r\n * If any other value will be converted to an Observable that emits such value.\r\n * - The Observable item will not be unwrapped.\r\n * - The Observable stream itself will be provided when the resolve is injected or bound elsewhere.\r\n *\r\n * #### Example:\r\n *\r\n * The `Transition` will wait for the `main.home` resolve observables to emit their first value.\r\n * Promises will be unwrapped and returned as observables before being provided to components.\r\n * ```js\r\n * var mainState = {\r\n * name: 'main',\r\n * resolve: mainResolves, // defined elsewhere\r\n * resolvePolicy: { async: RXWAIT },\r\n * }\r\n * ```\r\n */\r\nexport function RXWAIT(resolveFnValue: Observable<any> | any): Promise<Observable<any>> {\r\n if (!(resolveFnValue instanceof Observable)) {\r\n resolveFnValue = of(resolveFnValue);\r\n }\r\n\r\n const data$: Observable<any> = resolveFnValue.pipe(shareReplay(1));\r\n\r\n return data$\r\n .pipe(first())\r\n .toPromise()\r\n .then(() => {\r\n return data$;\r\n });\r\n}\r\n"]}
\No newline at end of file