angular - Observable.next() breaks loop -
this piece of code parses triples (not important) , should return 1 parking @ time. problem calling observer.next() breaks loop runs once. console.log doesn't called. i'm missing possible observer.next() breaks loop? there error or feature or plain wrong?
return observable.create(observer => { this.fetch.get(dataseturl).then(response => { // subjects parkings const parkingtriples = [], parkings = [], totalspacesparking = [], labels = []; (let index = 0; index < response.triples.length; index++) { if (response.triples[index].object === 'http://vocab.datex.org/terms#urbanparkingsite') { parkingtriples.push(response.triples[index]); } if (response.triples[index].predicate === 'http://vocab.datex.org/terms#parkingnumberofspaces') { totalspacesparking.push(response.triples[index]); } if (response.triples[index].predicate === 'http://www.w3.org/2000/01/rdf-schema#label') { labels.push(response.triples[index]); } } const _parkings = []; (let index = 0; index < parkingtriples.length; index++) { const totalspacesresult = find(totalspacesparking, (o) => { return o.subject === parkingtriples[index].subject }); const totalspaces = parseint(n3.util.getliteralvalue(totalspacesresult.object), 10); const labelresult = find(labels, (o) => { return o.subject === parkingtriples[index].subject }); const rdfslabel = n3.util.getliteralvalue(labelresult.object); const id = rdfslabel.replace(' ', '-').tolowercase(); observer.next(new parking(rdfslabel, parkingtriples[index].subject, id, totalspaces, dataseturl)); console.log(observer); } }) })
given updated code suggest debugging it. bug not in rx bits. have refactored code split between rx logic , response parsing:
function getparkings(dataseturl){ return rx.observable.defer(() => this.fetch.get(dataseturl)) .mergemap(response => parseparkingresponse(response)); } function parseparkingresponse(response) { const parkingtriples = [], parkings = [], totalspacesparking = [], labels = []; (let index = 0; index < response.triples.length; index++) { if (response.triples[index].object === 'http://vocab.datex.org/terms#urbanparkingsite') { parkingtriples.push(response.triples[index]); } if (response.triples[index].predicate === 'http://vocab.datex.org/terms#parkingnumberofspaces') { totalspacesparking.push(response.triples[index]); } if (response.triples[index].predicate === 'http://www.w3.org/2000/01/rdf-schema#label') { labels.push(response.triples[index]); } } const _parkings = []; (let index = 0; index < parkingtriples.length; index++) { const totalspacesresult = find(totalspacesparking, (o) => { return o.subject === parkingtriples[index].subject }); const totalspaces = parseint(n3.util.getliteralvalue(totalspacesresult.object), 10); const labelresult = find(labels, (o) => { return o.subject === parkingtriples[index].subject }); const rdfslabel = n3.util.getliteralvalue(labelresult.object); const id = rdfslabel.replace(' ', '-').tolowercase(); _parkings.push(new parking(rdfslabel, parkingtriples[index].subject, id, totalspaces, dataseturl)); } return _parkings; }
this make easier debug going on.
Comments
Post a Comment