Revue appel asynchrone à Papa Parse.
This commit is contained in:
parent
19c7994388
commit
318353c862
@ -94,30 +94,30 @@ export class ParserForCSV implements Parsers
|
||||
}
|
||||
|
||||
// async dans le cas d'une source distante
|
||||
// Et création d'une Promise car PapaParse utilise une fonction callback.
|
||||
public async parse(): Promise<any>
|
||||
{
|
||||
// Et création d'une Promise car PapaParse utilise des fonctions callback.
|
||||
public async parse(): Promise<any>
|
||||
{
|
||||
const parser=this, options=this.options;
|
||||
let parseContent="";
|
||||
if(parser._datasRemoteSource.url !== "")
|
||||
{
|
||||
parseContent=parser._datasRemoteSource.url;
|
||||
this._privateOptions.download=true;
|
||||
this._privateOptions.withCredentials=parser._datasRemoteSource.withCredentials;
|
||||
if(parser._datasRemoteSource.headers !== undefined)
|
||||
{
|
||||
this._privateOptions.downloadRequestHeaders={};
|
||||
for(let i=0; i< parser._datasRemoteSource.headers.length; i++)
|
||||
this._privateOptions.downloadRequestHeaders[parser._datasRemoteSource.headers[i].key]=parser._datasRemoteSource.headers[i].value;
|
||||
}
|
||||
}
|
||||
else if(parser._datas2Parse !== "")
|
||||
parseContent=parser._datas2Parse;
|
||||
else
|
||||
throw new Error(errors.parserNeedSource);
|
||||
|
||||
return new Promise((resolve,reject) =>
|
||||
{
|
||||
let parseContent="";
|
||||
if(parser._datasRemoteSource.url !== "")
|
||||
{
|
||||
parseContent=parser._datasRemoteSource.url;
|
||||
this._privateOptions.download=true;
|
||||
this._privateOptions.withCredentials=parser._datasRemoteSource.withCredentials;
|
||||
if(parser._datasRemoteSource.headers !== undefined)
|
||||
{
|
||||
this._privateOptions.downloadRequestHeaders={};
|
||||
for(let i=0; i< parser._datasRemoteSource.headers.length; i++)
|
||||
this._privateOptions.downloadRequestHeaders[parser._datasRemoteSource.headers[i].key]=parser._datasRemoteSource.headers[i].value;
|
||||
}
|
||||
}
|
||||
else if(parser._datas2Parse !== "")
|
||||
parseContent=parser._datas2Parse;
|
||||
else
|
||||
reject(new Error(errors.parserNeedSource));
|
||||
|
||||
Papa.parse(parseContent,
|
||||
{
|
||||
delimiter: options.delimiter,
|
||||
|
Loading…
Reference in New Issue
Block a user