本文整理汇总了TypeScript中rxjs/Rx.BehaviorSubject.asObservable方法的典型用法代码示例。如果您正苦于以下问题:TypeScript BehaviorSubject.asObservable方法的具体用法?TypeScript BehaviorSubject.asObservable怎么用?TypeScript BehaviorSubject.asObservable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Rx.BehaviorSubject
的用法示例。
在下文中一共展示了BehaviorSubject.asObservable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor() {
this._data = this.emptyData(); // Initialize session data with empty default values
let storedData = this.retrieve();
if (storedData) {
Object.assign(this._data, storedData);
}
this.dataSubject = new BehaviorSubject(this._data);
this.data = this.dataSubject.asObservable();
}
示例2: constructor
constructor() {
this.connections = [];
this._onUpdate = new BehaviorSubject([]);
this.onUpdate = this._onUpdate.asObservable();
}
示例3: constructor
constructor(
private zone: NgZone
) {
this.window = getWindow();
this.document = getDocument();
const initialFocus = this.document["visibilityState"] === "visible"
? DetailedFocusStates.TabFocus
: DetailedFocusStates.TabBlur;
this.detailedFocusSubject = new BehaviorSubject<DetailedFocusStates>(initialFocus);
// Wire up the detailed focus observable
//
this.detailedFocus$ = this.detailedFocusSubject
.asObservable()
.distinctUntilChanged();
// Now wire up the more generic observable by mapping the detailed values to the
// broader ones. We also add distinct until changed because we might get both
// a tab and window event fired, and we don't want to emit duplicates
//
this.focus$ = this.detailedFocus$
.map((focus) => {
switch (focus) {
case DetailedFocusStates.WindowFocus:
case DetailedFocusStates.TabFocus:
{
return FocusStates.Focus;
}
}
return FocusStates.Blur;
})
.distinctUntilChanged();
this.zone.run(() => {
this.document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible") {
this.detailedFocusSubject.next(DetailedFocusStates.TabFocus);
} else {
this.detailedFocusSubject.next(DetailedFocusStates.TabBlur);
}
});
/////////////////////////////////////////
// check if browser window has focus
let notIE = (this.document.documentMode === undefined),
isChromium = this.window.chrome;
if (notIE && !isChromium) {
// checks for Firefox and other NON IE Chrome versions
this.window.on("focusin",
() => {
setTimeout(() => {
this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);
},
300);
});
this.window.on("focusout", () => {
this.detailedFocusSubject.next(DetailedFocusStates.WindowBlur);
});
} else {
// checks for IE and Chromium versions
if (this.window.addEventListener) {
// bind focus event
this.window.addEventListener("focus", (event: any) => {
setTimeout(() => {
this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);
},
300);
},
false);
// bind blur event
this.window.addEventListener("blur", (event: any) => {
this.detailedFocusSubject.next(DetailedFocusStates.WindowBlur);
},
false);
} else {
// bind focus event
this.window.attachEvent("focus", (event: any) => {
setTimeout(() => {
this.detailedFocusSubject.next(DetailedFocusStates.WindowFocus);
},
//.........这里部分代码省略.........
示例4: getCurrentUser
getCurrentUser(): Observable<User> {
return this.currentUser.asObservable().share();
}
示例5: getTheme
getTheme() {
return this.theme.asObservable();
}
示例6: constructor
constructor() {
this._counties$ = new BehaviorSubject([]);
this.counties$ = this._counties$.asObservable();
}
示例7: getActiveTheme
getActiveTheme() {
return this.theme.asObservable();
}