Skip to content

Commit 743533a

Browse files
authored
Breaking Change: Remove SyncTasks from reactxp core and prefer ES6 promises (#1129)
* Remove SyncTasks from reactxp core and prefer ES6 promises Usage of ES6 promises is more standardized, using SyncTasks by default doesn't provide many consumers a large benefit. If they need SyncTasks promises, they can wrap in SyncTasks.fromThenable at the use site * Update reactxp-netinfo to remove SyncTasks * Update samples to use ES6 promises
1 parent 75e431b commit 743533a

38 files changed

+210
-193
lines changed

extensions/netinfo/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"tslint": "tslint -p tsconfig.json -r tslint.json -r ./node_modules/tslint-microsoft-contrib --fix || true"
1010
},
1111
"dependencies": {
12-
"@react-native-community/netinfo": "^3.2.0",
13-
"synctasks": "^0.3.3"
12+
"@react-native-community/netinfo": "^3.2.0"
1413
},
1514
"peerDependencies": {
1615
"reactxp": "^2.0.0-rc.1",

extensions/netinfo/src/common/Interfaces.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
* info. This was extracted from the reactxp core
99
*/
1010

11-
import * as SyncTasks from 'synctasks';
1211
import SubscribableEvent from 'subscribableevent';
1312

1413
import * as Types from './Types';
1514

1615
export abstract class NetInfo {
17-
abstract isConnected(): SyncTasks.Promise<boolean>;
18-
abstract getType(): SyncTasks.Promise<Types.DeviceNetworkType>;
16+
abstract isConnected(): Promise<boolean>;
17+
abstract getType(): Promise<Types.DeviceNetworkType>;
1918
connectivityChangedEvent = new SubscribableEvent<(isConnected: boolean) => void>();
2019
}
2120

extensions/netinfo/src/native-common/NetInfo.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
import * as RNNetInfo from '@react-native-community/netinfo';
11-
import * as SyncTasks from 'synctasks';
1211

1312
import * as Types from '../common/Types';
1413
import * as Interfaces from '../common/Interfaces';
@@ -24,20 +23,16 @@ export class NetInfo extends Interfaces.NetInfo {
2423
RNNetInfo.addEventListener(onEventOccurredHandler);
2524
}
2625

27-
isConnected(): SyncTasks.Promise<boolean> {
28-
const deferred = SyncTasks.Defer<boolean>();
29-
30-
RNNetInfo.fetch().then((state: RNNetInfo.NetInfoState) => {
31-
deferred.resolve(state.isConnected);
26+
isConnected(): Promise<boolean> {
27+
return RNNetInfo.fetch().then((state: RNNetInfo.NetInfoState) => {
28+
return state.isConnected;
3229
}).catch(() => {
33-
deferred.reject('NetInfo.isConnected.fetch() failed');
30+
return Promise.reject('NetInfo.isConnected.fetch() failed');
3431
});
35-
36-
return deferred.promise();
3732
}
3833

39-
getType(): SyncTasks.Promise<Types.DeviceNetworkType> {
40-
return SyncTasks.fromThenable(RNNetInfo.fetch()).then((state: RNNetInfo.NetInfoState) => {
34+
getType(): Promise<Types.DeviceNetworkType> {
35+
return RNNetInfo.fetch().then((state: RNNetInfo.NetInfoState) => {
4136
return NetInfo._getNetworkTypeFromConnectionInfo(state);
4237
});
4338
}

extensions/netinfo/src/web/NetInfo.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* Web-specific implementation of the cross-platform Video abstraction.
88
*/
99

10-
import * as SyncTasks from 'synctasks';
11-
1210
import * as Types from '../common/Types';
1311
import * as Interfaces from '../common/Interfaces';
1412

@@ -27,12 +25,12 @@ export class NetInfo extends Interfaces.NetInfo {
2725
}
2826
}
2927

30-
isConnected(): SyncTasks.Promise<boolean> {
31-
return SyncTasks.Resolved(navigator.onLine);
28+
isConnected(): Promise<boolean> {
29+
return Promise.resolve(navigator.onLine);
3230
}
3331

34-
getType(): SyncTasks.Promise<Types.DeviceNetworkType> {
35-
return SyncTasks.Resolved(Types.DeviceNetworkType.Unknown);
32+
getType(): Promise<Types.DeviceNetworkType> {
33+
return Promise.resolve(Types.DeviceNetworkType.Unknown);
3634
}
3735
}
3836

extensions/netinfo/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"strict": true,
1212
"outDir": "dist/",
1313
"lib": [
14+
"es2015.promise",
1415
"es5",
1516
"dom"
1617
],

package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"lodash": "^4.17.15",
1616
"prop-types": "^15.7.2",
1717
"rebound": "^0.1.0",
18-
"subscribableevent": "^1.0.1",
19-
"synctasks": "^0.3.3"
18+
"subscribableevent": "^1.0.1"
2019
},
2120
"peerDependencies": {
2221
"react": "^16.0",

samples/ImageList/src/stores/ImageStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class ImageStore extends StoreBase {
2020
private _searchQuery = '';
2121
private _images: Image[] = [];
2222

23-
private _request: SyncTasks.STPromise<void> | null = null;
23+
private _request: SyncTasks.Promise<void> | null = null;
2424

2525
@autoSubscribe
2626
getImages() {
@@ -68,7 +68,7 @@ export class ImageStore extends StoreBase {
6868
this._request = this._searchImages(searchQuery);
6969
}
7070

71-
private _searchImages(query: string): SyncTasks.STPromise<void> {
71+
private _searchImages(query: string): SyncTasks.Promise<void> {
7272
return GiphyClient.searchImages(query)
7373
.then(images => {
7474
this._images = images;

samples/RXPTest/src/Tests/LocationTest.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class LocationView extends RX.Component<RX.CommonProps, LocationState> {
158158
polledPositionHistory: this.state.polledPositionHistory +
159159
'(' + this._formatError(err.code as RX.Types.LocationErrorType) + ')\n'
160160
});
161-
}).always(() => {
161+
}).finally(() => {
162162
sampleCount++;
163163
if (sampleCount < totalSamplesInTest) {
164164
_.delay(() => {

samples/RXPTest/src/Tests/NetworkTest.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
import _ = require('lodash');
66
import RX = require('reactxp');
7-
import RXNetInfo, { Types as RXNetInfoTypes } from 'reactxp-netinfo'
7+
import RXNetInfo, { Types as RXNetInfoTypes } from 'reactxp-netinfo';
88

99
import * as CommonStyles from '../CommonStyles';
10-
import { Test, TestResult, TestType } from '../Test';
10+
import { Test, TestType } from '../Test';
1111

1212
const _styles = {
1313
container: RX.Styles.createViewStyle({

0 commit comments

Comments
 (0)