根据RxJS 5 MIGRATION.md,它看起来像shareReplay()被删除了.
.publishReplay(1).refCount()忠实地复制行为?基本上我需要将最新的单个数据集重播给任何新订阅者.我是Observable样式编程的新手.我有一个问题:我希望在组件之间跨应用程序共享用户信息 - 我使用BehaviorSubject来共享此信息.这是通过将BehaviorSubject共享为AuthInfo来启发的.如果我可以在我的应用程序组件中共享包含uid的AuthInfo,为什么我可以使用它来共享我的用户对象数据?
问题是,用户对象,我是从Firebase获得的.所以它是一个Observable,我不知道如何将它分配给一个行为主题.所以这是我尝试的代码:
@Injectable()
export class AuthService {
static UNKNOWN_USER = new AuthInfo(null);
static EMPTY_USER = new User(null, null, null, null);
authInfo$: BehaviorSubject<AuthInfo> = new BehaviorSubject<AuthInfo>(AuthService.UNKNOWN_USER);
userInfo$: BehaviorSubject<User> = new BehaviorSubject<User>(AuthService.EMPTY_USER);
constructor(private auth: FirebaseAuth, private db:AngularFireDatabase, @Inject(FirebaseRef) fb) {
//firebase way to see if user is login or not
this.auth.subscribe(user => {
if (user) {
const authInfo = new AuthInfo(user.uid);
this.authInfo$.next(authInfo);
//This is the part I do not know how to do
[OPTION 1]: this.userInfo$.next(findUserByuid(user.uid)) ?? - error
[OPTION …Run Code Online (Sandbox Code Playgroud)