This commit is contained in:
Josep M Sobrepere 2020-05-27 23:20:12 +02:00
parent a1c64db22f
commit f719548d94
3 changed files with 11 additions and 7 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@josepot/react-rxjs",
"version": "0.1.3",
"version": "0.1.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,5 +1,5 @@
{
"version": "0.1.3",
"version": "0.1.4",
"repository": {
"type": "git",
"url": "git+https://github.com/josepot/react-rxjs.git"

View File

@ -1,6 +1,6 @@
import { useEffect, useState } from "react"
import { Observable, of } from "rxjs"
import { delay, takeUntil } from "rxjs/operators"
import { Observable, of, race } from "rxjs"
import { delay, take, mapTo } from "rxjs/operators"
import {
StaticObservableOptions,
defaultStaticOptions,
@ -66,9 +66,13 @@ export function connectFactoryObservable<
setValue(initialValue)
} else if (suspenseTime < Infinity) {
subscription.add(
of(initialValue)
.pipe(delay(suspenseTime), takeUntil(sharedObservable$))
.subscribe(setValue),
race(
of(initialValue).pipe(delay(suspenseTime)),
sharedObservable$.pipe(
take(1),
mapTo((x: I | O) => x),
),
).subscribe(setValue),
)
}