本文整理汇总了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();
}
开发者ID:arner,项目名称:saevis,代码行数:4,代码来源:authentication.service.ts
示例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);
};
开发者ID:cybernetics,项目名称:devmod,代码行数:67,代码来源:developer-observable.ts
示例3: setTimeout
setTimeout(() => {
subject$.error("error " + i);
error = true;
}, 1000)
开发者ID:chrigu,项目名称:rxjs-experiments,代码行数:4,代码来源:behaviorSubject.error.ts
示例4:
export const deselectActivity = () => {
selectedActivity$().next({});
}
开发者ID:kpreeti096,项目名称:BotFramework-Emulator,代码行数:3,代码来源:settings.ts
示例5: resolve
.subscribe(response => {
this.onBoardChanged.next(this.board);
resolve(this.board);
}, reject);
开发者ID:karthik12ui,项目名称:fuse-angular-full,代码行数:4,代码来源:scrumboard.service.ts
示例6: getSnapshot
// ---
// PUBLIC METHODS.
// ---
// I get the current state snapshot.
public getSnapshot() : StateType {
return( this.stateSubject.getValue() );
}
开发者ID:bennadel,项目名称:JavaScript-Demos,代码行数:10,代码来源:simple.store.ts
示例7: resolve
.subscribe((response: any) => {
this.orders = response;
this.onOrdersChanged.next(this.orders);
resolve(response);
}, reject);
开发者ID:karthik12ui,项目名称:fuse-angular-full,代码行数:5,代码来源:orders.service.ts
示例8: resolve
.subscribe((response: any) => {
this.tableData = response;
console.log("data in getTable",this.tableData),
this.onDataChanged.next(this.tableData);
resolve(response);
}, reject);
开发者ID:,项目名称:,代码行数:6,代码来源:
示例9: delete
delete() {
this.tokenSubject.next("");
}
开发者ID:urandom,项目名称:readeef,代码行数:3,代码来源:auth.ts
示例10: tokenObservable
tokenObservable() : Observable<string> {
return this.tokenSubject.pipe(
map(auth => (auth || "").replace("Bearer ", "")),
throttle(v => interval(2000)),
);
}
开发者ID:urandom,项目名称:readeef,代码行数:6,代码来源:auth.ts
注:本文中的rxjs.BehaviorSubject类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论