Rxjs introduced in the Notification

timer (0, 1000) // timer, a value of each emitting 1000ms, the delay time of the initial transmission values 0s; 
.pipe (
Take (. 5), // take the first 5 values
takeWhile (value => value> -1 ) // long as one is not greater than 1; i.e. Complete execution; end Next
Materialize () // specific, each value is converted to a Notification object
)
.subscribe ({
Next (value) {
the console.log (value );
}
});
results are as follows:

  --------------------------------------------------------------------------------------------------------------

  • materializeIt is to Observable弹射convert the data into an event Notificationobject / subject;
  • dematerializeIt is Notification物件/对象converted to Observablethe event information.
-------------------------------------------------------------------------
timer (0, 1000) // timer, a value of each emitting 1000ms, the delay time of the initial transmission values 0s; 
.pipe (
Take (. 5), // take the first 5 values
takeWhile (value => value> -1 ) // long as one is not greater than 1; i.e. Complete execution; end Next
materialize () // specific, each value is converted to a Notification objects
dematerialize (), with the opposite // materialize operation; Notification objects into the Object of Observable
)
.subscribe ({
Next (value) {
the console.log (value);
}
});
Results are as follows:
of(1, 2, 3, 'a', 4)
.pipe(
materialize(),
map(x => x.kind === NotificationKind.COMPLETE ? x : new Notification(x.kind, x.value + ' hello'))
)
.subscribe(value => {
console.log(value);
});

Through the above example, we know a Notificationleast contains several information

  1. kind: Current status information: N (Next), E (Error), C (Complete)
  2. value: Value / data
  3. hasValue: Is there include data
  4. error: Error message

Also can be used as new Notification()the way of the establishment.

 

 
 

Guess you like

Origin www.cnblogs.com/szy-du/p/11141188.html