apache / apache/cordova-plugin-file

Promises

Open
#637 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
744
Forks
754
Avg merge
3d 4h
Merged PRs (30d)
1

Description

# Feature Request
I want to add Promise functionality to this plugin and have some questions.

From my point, Promises are save to add natively, because:
- For Android the minimum supported Android version is 7.0 since cordova-android 12. Promises are supported since [Version 4.4.4](https://caniuse.com/?search=Promise)
- For iOS, WKWebView is the required minimum. Promises are supported since [iOS 8](https://caniuse.com/?search=Promise).

Here a sample of a conversion i would make.

Old code:
```javascript
FileEntry.prototype.file = function (successCallback, errorCallback) {
const localURL = this.toInternalURL();
const win = successCallback && function (f) {
const file = new File(f.name, localURL, f.type, f.lastModifiedDate, f.size);
successCallback(file);
};
const fail = errorCallback && function (code) {
errorCallback(new FileError(code));
};
exec(win, fail, 'File', 'getFileMetadata', [localURL]);
};
```

New code:
```javascript
FileEntry.prototype.file = function (successCallback, errorCallback) {
return new Promise((resolve, reject) => {
const localURL = this.toInternalURL();
const win = function (f) {
const file = new File(f.name, localURL, f.type, f.lastModifiedDate, f.size);
if (successCallback) successCallback(file);
resolve(file);
};
const fail = function (code) {
if (errorCallback) errorCallback(new FileError(code));
reject(new FileError(code));
};
exec(win, fail, 'File', 'getFileMetadata', [localURL]);
});
};
```
Would it be fine like this?

Regards

Contributor guide

Open the contributing guide

Research direction

The concrete entry point shown is FileEntry.prototype.file in the issue sample; begin by reviewing the plugin's existing callback-based APIs and the stated Android and iOS compatibility constraints. The Promise API scope and expected behavior still need agreement in the discussion, and done would require an agreed implementation plan plus validation for the affected APIs.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, ios, javascript
Domain
mobile-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.