Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking Change: Remove SyncTasks from reactxp core and prefer ES6 promises #1129

Merged
merged 3 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions extensions/netinfo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"tslint": "tslint -p tsconfig.json -r tslint.json -r ./node_modules/tslint-microsoft-contrib --fix || true"
},
"dependencies": {
"@react-native-community/netinfo": "^3.2.0",
"synctasks": "^0.3.3"
"@react-native-community/netinfo": "^3.2.0"
},
"peerDependencies": {
"reactxp": "^2.0.0-rc.1",
Expand Down
5 changes: 2 additions & 3 deletions extensions/netinfo/src/common/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
* info. This was extracted from the reactxp core
*/

import * as SyncTasks from 'synctasks';
import SubscribableEvent from 'subscribableevent';

import * as Types from './Types';

export abstract class NetInfo {
abstract isConnected(): SyncTasks.Promise<boolean>;
abstract getType(): SyncTasks.Promise<Types.DeviceNetworkType>;
abstract isConnected(): Promise<boolean>;
abstract getType(): Promise<Types.DeviceNetworkType>;
connectivityChangedEvent = new SubscribableEvent<(isConnected: boolean) => void>();
}

Expand Down
17 changes: 6 additions & 11 deletions extensions/netinfo/src/native-common/NetInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

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

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

isConnected(): SyncTasks.Promise<boolean> {
const deferred = SyncTasks.Defer<boolean>();

RNNetInfo.fetch().then((state: RNNetInfo.NetInfoState) => {
deferred.resolve(state.isConnected);
isConnected(): Promise<boolean> {
return RNNetInfo.fetch().then((state: RNNetInfo.NetInfoState) => {
return state.isConnected;
}).catch(() => {
deferred.reject('NetInfo.isConnected.fetch() failed');
return Promise.reject('NetInfo.isConnected.fetch() failed');
});

return deferred.promise();
}

getType(): SyncTasks.Promise<Types.DeviceNetworkType> {
return SyncTasks.fromThenable(RNNetInfo.fetch()).then((state: RNNetInfo.NetInfoState) => {
getType(): Promise<Types.DeviceNetworkType> {
return RNNetInfo.fetch().then((state: RNNetInfo.NetInfoState) => {
return NetInfo._getNetworkTypeFromConnectionInfo(state);
});
}
Expand Down
10 changes: 4 additions & 6 deletions extensions/netinfo/src/web/NetInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Web-specific implementation of the cross-platform Video abstraction.
*/

import * as SyncTasks from 'synctasks';

import * as Types from '../common/Types';
import * as Interfaces from '../common/Interfaces';

Expand All @@ -27,12 +25,12 @@ export class NetInfo extends Interfaces.NetInfo {
}
}

isConnected(): SyncTasks.Promise<boolean> {
return SyncTasks.Resolved(navigator.onLine);
isConnected(): Promise<boolean> {
return Promise.resolve(navigator.onLine);
}

getType(): SyncTasks.Promise<Types.DeviceNetworkType> {
return SyncTasks.Resolved(Types.DeviceNetworkType.Unknown);
getType(): Promise<Types.DeviceNetworkType> {
return Promise.resolve(Types.DeviceNetworkType.Unknown);
}
}

Expand Down
1 change: 1 addition & 0 deletions extensions/netinfo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"strict": true,
"outDir": "dist/",
"lib": [
"es2015.promise",
"es5",
"dom"
],
Expand Down
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"lodash": "^4.17.15",
"prop-types": "^15.7.2",
"rebound": "^0.1.0",
"subscribableevent": "^1.0.1",
"synctasks": "^0.3.3"
"subscribableevent": "^1.0.1"
},
"peerDependencies": {
"react": "^16.0",
Expand Down
4 changes: 2 additions & 2 deletions samples/ImageList/src/stores/ImageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ImageStore extends StoreBase {
private _searchQuery = '';
private _images: Image[] = [];

private _request: SyncTasks.STPromise<void> | null = null;
private _request: SyncTasks.Promise<void> | null = null;

@autoSubscribe
getImages() {
Expand Down Expand Up @@ -68,7 +68,7 @@ export class ImageStore extends StoreBase {
this._request = this._searchImages(searchQuery);
}

private _searchImages(query: string): SyncTasks.STPromise<void> {
private _searchImages(query: string): SyncTasks.Promise<void> {
return GiphyClient.searchImages(query)
.then(images => {
this._images = images;
Expand Down
2 changes: 1 addition & 1 deletion samples/RXPTest/src/Tests/LocationTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class LocationView extends RX.Component<RX.CommonProps, LocationState> {
polledPositionHistory: this.state.polledPositionHistory +
'(' + this._formatError(err.code as RX.Types.LocationErrorType) + ')\n'
});
}).always(() => {
}).finally(() => {
sampleCount++;
if (sampleCount < totalSamplesInTest) {
_.delay(() => {
Expand Down
4 changes: 2 additions & 2 deletions samples/RXPTest/src/Tests/NetworkTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

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

import * as CommonStyles from '../CommonStyles';
import { Test, TestResult, TestType } from '../Test';
import { Test, TestType } from '../Test';

const _styles = {
container: RX.Styles.createViewStyle({
Expand Down
2 changes: 1 addition & 1 deletion samples/RXPTest/src/Tests/StorageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class StorageBasicTest implements AutoExecutableTest {
});
}).catch(error => {
results.errors.push('Received unexpected error from RX.Storage');
}).always(() => {
}).finally(() => {
complete(results);
});
}
Expand Down
3 changes: 1 addition & 2 deletions samples/RXPTest/src/Tests/UserInterfaceTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import _ = require('lodash');
import RX = require('reactxp');
import SyncTasks = require('synctasks');

import * as CommonStyles from '../CommonStyles';
import { AutoExecutableTest, TestResult, TestType } from '../Test';
Expand Down Expand Up @@ -182,7 +181,7 @@ class UserInterfaceView extends RX.Component<RX.CommonProps, UserInterfaceState>
});

// Wait for all async tasks to complete.
SyncTasks.all([measureTask, multiplierTask]).then(() => {
Promise.all([measureTask, multiplierTask]).then(() => {
// Mark the test as complete.
complete(result);
});
Expand Down
8 changes: 7 additions & 1 deletion samples/RXPTest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
"noImplicitReturns": true,
"outDir": "./dist/",
"types" : ["lodash", "react", "react-dom"],
"strict": true
"strict": true,
"lib": [
"es2015.promise",
"es2018.promise",
"es5",
"dom"
]
},
"include": [
"./src/**/*"
Expand Down
3 changes: 1 addition & 2 deletions samples/TodoList/src/ts/app/AppBootstrapperNative.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { DbProvider } from 'nosqlprovider';
import { CordovaNativeSqliteProvider } from 'nosqlprovider/dist/CordovaNativeSqliteProvider';
import { InMemoryProvider } from 'nosqlprovider/dist/InMemoryProvider';
import * as RX from 'reactxp';
import * as SyncTasks from 'synctasks';

import AppBootstrapper from './AppBootstrapper';

Expand All @@ -32,7 +31,7 @@ class AppBootstrapperNative extends AppBootstrapper {
];
}

protected _getInitialUrl(): SyncTasks.Promise<string | undefined> {
protected _getInitialUrl(): Promise<string | undefined> {
return RX.Linking.getInitialUrl();
}
}
Expand Down
5 changes: 2 additions & 3 deletions samples/TodoList/src/ts/app/AppBootstrapperWeb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { DbProvider } from 'nosqlprovider';
import { IndexedDbProvider } from 'nosqlprovider/dist/IndexedDbProvider';
import { InMemoryProvider } from 'nosqlprovider/dist/InMemoryProvider';
import { WebSqlProvider } from 'nosqlprovider/dist/WebSqlProvider';
import * as SyncTasks from 'synctasks';

import AppBootstrapper from './AppBootstrapper';

Expand All @@ -36,8 +35,8 @@ class AppBootstrapperWeb extends AppBootstrapper {
];
}

protected _getInitialUrl(): SyncTasks.Promise<string | undefined> {
return SyncTasks.Resolved(window.location.href);
protected _getInitialUrl(): Promise<string | undefined> {
return Promise.resolve(window.location.href);
}
}

Expand Down
17 changes: 7 additions & 10 deletions samples/TodoList/src/ts/controls/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import * as assert from 'assert';
import * as RX from 'reactxp';
import { ComponentBase } from 'resub';
import * as SyncTasks from 'synctasks';

import KeyCodes from '../utilities/KeyCodes';
import { Colors } from '../app/Styles';
Expand Down Expand Up @@ -198,18 +197,16 @@ export default class Modal extends ComponentBase<ModalProps, ModalState> {
});
}

static dismissAnimated(modalId: string): SyncTasks.Promise<void> {
static dismissAnimated(modalId: string): Promise<void> {
let modal = Modal._visibleModalMap[modalId];
if (!modal) {
return SyncTasks.Rejected('Modal ID not found');
return Promise.reject('Modal ID not found');
}

let deferred = SyncTasks.Defer<void>();
modal._animateClose(() => {
RX.Modal.dismiss(modalId);
deferred.resolve(void 0);
});

return deferred.promise();
return new Promise<void>(resolve => {
modal._animateClose(() => {
RX.Modal.dismiss(modalId);
resolve(void 0);
});
}
}
3 changes: 1 addition & 2 deletions samples/TodoList/src/ts/controls/SimpleDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import * as _ from 'lodash';
import * as RX from 'reactxp';
import { ComponentBase } from 'resub';
import * as SyncTasks from 'synctasks';

import KeyCodes from '../utilities/KeyCodes';
import Modal from './Modal';
Expand Down Expand Up @@ -225,7 +224,7 @@ export default class SimpleDialog extends ComponentBase<SimpleDialogProps, RX.St
return false;
}

static dismissAnimated(dialogId: string): SyncTasks.Promise<void> {
static dismissAnimated(dialogId: string): Promise<void> {
return Modal.dismissAnimated(dialogId);
}
}
20 changes: 0 additions & 20 deletions samples/TodoList/src/ts/utilities/ShimHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
* Helpers to shim various aspects of the app for React Native.
*/

import * as assert from 'assert';
import * as SyncTasks from 'synctasks';

import { Options as ReSubOptions } from 'resub';

import ExceptionReporter from './ExceptionReporter';
Expand All @@ -19,23 +16,6 @@ export function shimEnvironment(isDev: boolean, isNative: boolean) {
ReSubOptions.development = isDev;
ReSubOptions.preventTryCatchInRender = true;

// Set SyncTasks exception rules early. We don't want to swallow any exceptions.
SyncTasks.config.catchExceptions = false;
SyncTasks.config.exceptionHandler = (err: Error) => {
if (!err) {
return;
}

assert.fail('Unhandled exception: ' + JSON.stringify(err));

// tslint:disable-next-line
throw err;
};

SyncTasks.config.unhandledErrorHandler = (err: any) => {
assert.fail('Unhandled rejected SyncTask. Error: ' + JSON.stringify(err));
};

// Install our exception-reporting alert on local builds.
let exceptionReporter = new ExceptionReporter();
if (isDev) {
Expand Down
Loading