Search code examples
javascriptrxjsreactive-extensions-js

Unable to create Rx.Observable from JS event


I'm trying to figure out how to use rx.js with a dog-simple example, but can't figure out what reference or file I'm missing that means it isn't working.

<!DOCTYPE html>
<html>
<head>
    <title>Empty</title>
    <script src="/Scripts/rx.js"></script>
</head>
<body>
    <script>
        var thing = Rx.Observable.fromEvent(document, 'keydown');
    </script>
</body>
</html>

That's literally it. The script line correctly loads a local copy of rx.js 2.4.1 freshly downloaded from nuget.

I'm getting the error Rx.Observable.fromEvent is not a function, so I'm assuming that there is a missing reference.

It might just be the time of night, but I'm struggling to see what I'm doing wrong. Any help?


Solution

  • Resolved by downloading and using additional Rx files rx.async.js and rx.binding.js like so:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Empty</title>
        <script src="/Scripts/rx.js"></script>
        <script src="/Scripts/rx.async.js"></script>
        <script src="/Scripts/rx.binding.js"></script>
    </head>
    <body>
        <script>
            var thing = Rx.Observable.fromEvent(document, 'keydown');
        </script>
    </body>
    </html>