jimhigson / oboe.js

A streaming approach to JSON. Oboe.js speeds up web applications by providing parsed objects before the response completes.
http://oboejs.com
Other
4.77k stars 209 forks source link

Done function executes for each root object instead of final object response #224

Open rahultailwal opened 3 years ago

rahultailwal commented 3 years ago

Hi, I have an api where we have direct root json objects like below. I have to fetch each object data from the api and push into array and also want to know when all data is completed. Basically its Newline delimited JSON streaming

{id : 1, name: 'Test1'} {id : 2, name: 'Test1'} {id : 3, name: 'Test1'} {id : 4, name: 'Test1'}

I am using rsjx with oboe to do that. If i use the below then for each object I am getting done event called it should be printed at the end of 4th json object. How can we achieve this with Oboe, In the given examples there is no example for direct json object all are within some json object array or normal text. Please update

import { Observable } from 'rxjs' import oboe from 'oboe'

const oboeService = { streamObservable(input) { return new Observable(obs => { const stream = oboe(input) stream.node('!', data => obs.next(data)) stream.done(() => console.log('donedd')) // To test when done is printed stream.fail(e => obs.error(e)) }) }, } export default oboeService