本文整理匯總了TypeScript中rxjs.BehaviorSubject類的典型用法代碼示例。如果您正苦於以下問題:TypeScript BehaviorSubject類的具體用法?TypeScript BehaviorSubject怎麽用?TypeScript BehaviorSubject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了BehaviorSubject類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor(private authService: AuthService, private router: Router) {
this.currentUserSubject = new BehaviorSubject<User>(JSON.parse(localStorage.getItem('currentUser')));
this.currentUser = this.currentUserSubject.asObservable();
}
示例2: function
return function(target: Object, key: string) {
if (!isDebugMode()) {
return;
}
const takeLast = config.takeLast || 5;
const label = config.label || key;
const metaTarget = target.constructor;
const debugObservables = getOwnMetadata(OBSERVABLE_KEY, metaTarget) || [];
const valueHistory = new BehaviorSubject([]);
let observable = target[key];
let lastEmissions = [];
const get = function() {
return observable;
};
const set = function(newValue: Observable<any>) {
lastEmissions = [];
valueHistory.next(lastEmissions);
// Patch subscription method so we can log when someone subscribes
if (config.logSubscriptions) {
const orig = newValue.subscribe;
newValue.subscribe = function(...args) {
console.log(
`${label} subscribed to:\n`,
new Error().stack
.split('\n')
.slice(5) // Skip this call and the ones up to devmod's monkey patch
.map(v => `\t ${v.trim()}`)
.join('\n')
);
return orig.call(newValue, ...args);
};
}
// Store previously emitted values in BehaviorSubject
observable = newValue.pipe(
tap(v => {
if (config.log) {
console.log(`${label} emitted`, v);
}
lastEmissions = lastEmissions
.concat({
at: new Date(),
value: v
})
.slice(-1 * takeLast);
valueHistory.next(lastEmissions);
})
);
};
Object.defineProperty(target, key, {
get,
set,
enumerable: true,
configurable: true
});
debugObservables.push({ key, obs: valueHistory, takeLast, label });
defineMetadata(OBSERVABLE_KEY, debugObservables, metaTarget);
};
示例3: setTimeout
setTimeout(() => {
subject$.error("error " + i);
error = true;
}, 1000)
示例4:
export const deselectActivity = () => {
selectedActivity$().next({});
}
示例5: resolve
.subscribe(response => {
this.onBoardChanged.next(this.board);
resolve(this.board);
}, reject);
示例6: getSnapshot
// ---
// PUBLIC METHODS.
// ---
// I get the current state snapshot.
public getSnapshot() : StateType {
return( this.stateSubject.getValue() );
}
示例7: resolve
.subscribe((response: any) => {
this.orders = response;
this.onOrdersChanged.next(this.orders);
resolve(response);
}, reject);
示例8: resolve
.subscribe((response: any) => {
this.tableData = response;
console.log("data in getTable",this.tableData),
this.onDataChanged.next(this.tableData);
resolve(response);
}, reject);
示例10: tokenObservable
tokenObservable() : Observable<string> {
return this.tokenSubject.pipe(
map(auth => (auth || "").replace("Bearer ", "")),
throttle(v => interval(2000)),
);
}