Skip to main content

dematerialize

函数签名: dematerialize(): Observable

将 notification 对象转换成 notification 值。

示例

示例 1: 将 notifications 转换成值。

( StackBlitz | jsBin | jsFiddle )

// RxJS v6+
import { from, Notification } from 'rxjs';
import { dematerialize } from 'rxjs/operators';

// 发出 next 和 error 通知
const source = from([
Notification.createNext('SUCCESS!'),
Notification.createError('ERROR!')
]).pipe(
// 将 notification 对象转换成 notification 值
dematerialize()
)

// 输出: 'NEXT VALUE: SUCCESS' 'ERROR VALUE: 'ERROR!'
const subscription = source.subscribe({
next: val => console.log(`NEXT VALUE: ${val}`),
error: val => console.log(`ERROR VALUE: ${val}`)
});

其他资源


📁 源码: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/demterialize.ts