Skip to content
richardszalay edited this page May 20, 2011 · 7 revisions

Converts all messages, including onError and onComplete, into value messages (of type raix.reactive.Notification). To reverse the process, see [dematerialize].

function materialize() : IObservable.<Notification>

Remarks

The messages are converted into instances of Notification, which can be re-applied to an IObserver by calling Notificaton.acceptWith or to methods directly by calling Notification.accept. Doing so will call the appropriate method (onNext, onCompleted, onError)

The Notification type can be accessed using the kind property, which will have a value of NotificationKind.ON_NEXT, NotificationKind.ON_ERROR, or NotificationKind.ON_COMPLETED

Values can be accessed directly from Notification using the hasValue and value properties.

An error can be accessed directly from Notification using the error property.

The returned sequence completes when the source sequence completes or errors, after it has sent the appropriate Notification

The returned sequence does not error

Marble Diagrams

(o,x,/) = Instances of Notification (next, error, complete)

xs    ──o─────o─────o───/
        │     │     │   │
        │     │     │   │
ys    ──o─────o─────o───o/
       (o)   (o)   (o) (/)

xs    ──o─────o─────o───x
        │     │     │   │
        │     │     │   │
ys    ──o─────o─────o───o/
       (o)   (o)   (o) (x)

Return Value

IObservable.<Notification>

Examples

Observable.range(1, 3).materialize()
    .subscribe(
        function(x : Notification) : void
        {
            switch(x.kind)
            {
                case NotificationKind.ON_NEXT:
                    trace("next notification - " + x.value.toString());
                    break;
                case NotificationKind.ON_ERROR:
                    trace("error notification - " + x.error.toString());
                    break;
                case NotificationKind.ON_COMPLETED:
                    trace("completed notification");
                    break;
            }
        },
        function():void { trace("onCompleted call"); }
    );

    // Trace output is:
    // next notification - 1
    // next notification - 2
    // next notification - 3
    // completed notification
    // onCompleted call
Observable.range(1, 3)
    .concat([
        Observable.error(new Error("boo"))
    ])
    .materialize()
    .subscribe(
        function(x : Notification) : void
        {
            switch(x.kind)
            {
                case NotificationKind.ON_NEXT:
                    trace("next notification - " + x.value.toString());
                    break;
                case NotificationKind.ON_ERROR:
                    trace("error notification - " + x.error.toString());
                    break;
                case NotificationKind.ON_COMPLETED:
                    trace("completed notification");
                    break;
            }
        },
        function():void { trace("onCompleted call"); }
    );

    // Trace output is:
    // next notification - 1
    // next notification - 2
    // next notification - 3
    // error notification - boo
    // onCompleted call
Clone this wiki locally