Module-documentation

version 1.0.0
module: itsa-io
maintanance: Marco Asbreuk
home
all modules

Streamed IO.read()

Get streamed dataobject from the server using ITSA.IO.read() using streamback.

Click on the button to initiate the request.

Code-example:

<body>
    <div id="container">
        <button id="button-get">Click me get data</button>
    </div>
    <div id="target-container"></div>
</body>
<script src="itsabuild-min.js"></script>
<script>
    var url = 'http://servercors.itsa.io/example/stream',
        container = document.getElementById('target-container'),
        writeResponse, writeResponse, streamFn;

    readyResponse = function(data) {
        // `data` has all the data, but we don't use it here.
        container.append('<br>READY');
    };

    errorResponse = function(e) {
        container.setText(e.message);
    };

    streamFn = function(data) {
        // data should be an array
        if (Array.isArray(data)) {
            data.forEach(function(item) {
                container.append(JSON.stringify(item)+'<br>');
            });
        }
    };

    ITSA.Event.after(
        'tap',
        function() {
            container.innerHTML = '';
            ITSA.IO.read(url, {example: 1}, {streamback: streamFn}).then(readyResponse, errorResponse);
        },
        '#button-get'
    );
</script>
API Docs