Привет, у меня есть функция, которая должна возвращать Array, в приведенной ниже функции this.cordovaFile.readAsArrayBuffer(this.cordovaFile.dataDirectory, storageId)
фактически возвращает массив Promise, который я преобразовываю в Observable и сохраняю в переменную timesheetArray
, а теперь timesheetArray
возвращает массив Observable но я просто хочу вернуть только массив. Ниже приведен код
Пожалуйста, помогите, если он возвращает только массив, мне не нужно никуда его менять, потому что эта функция используется в приложении
public getAllTimesheets(): TimesheetModel[] {
const storageId = TIMESHEET_KEYS.ALL_TIMESHEET;
const timesheetArray = from(
this.cordovaFile
.readAsArrayBuffer(this.cordovaFile.dataDirectory, storageId)
.then((compressedTimesheet) => {
const start = moment();
const uint8array = new Uint8Array(compressedTimesheet);
const jsonTimeSheet = this.LZString.decompressFromUint8Array(uint8array);
this.log.debug(`LocalStorageMaterialService: getMaterials() from files: Decompression took ${moment().subtract(start.valueOf()).valueOf()} ms`);
return <TimesheetModel[] > JSON.parse(jsonTimeSheet) || [];
})
.catch((error) => {
this.log.debug('LocalStorageMaterialService: Retrieving materials from file storage was not possible: ', JSON.stringify(error));
return [];
})
)
timesheetArray.subscribe((timesheet) => {
// here how to return an Array ??
});
}
и только один пример, почему я хочу вернуть массив, но не наблюдаемый
let matchedTimesheet = _.find<TimesheetModel>(this.getAllTimesheets() ,
(timesheet) => travelToDate
&& timesheet.startOfWork.isSame(travelToDate.startDate.value, 'days')
); ```
here in the above code it is expecting an array but not Observable., I can do it by subscribing here also , but if the function returns an array instead of observable, then i need to change everywhere