Skip to content

Commit 00a1df3

Browse files
committed
chore: cleanup
1 parent e3cb9c4 commit 00a1df3

File tree

11 files changed

+180
-145
lines changed

11 files changed

+180
-145
lines changed

demo-angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@angular/platform-browser-dynamic": "~8.0.0",
2323
"@angular/router": "~8.0.0",
2424
"nativescript-angular": "~8.0.0",
25-
"nativescript-async": "file:../src",
25+
"nativescript-http-async": "file:../src",
2626
"nativescript-theme-core": "~1.0.4",
2727
"reflect-metadata": "~0.1.12",
2828
"rxjs": "~6.5.0",

demo-angular/src/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
22
import { NativeScriptModule } from 'nativescript-angular/nativescript.module';
3-
import { NativeScriptAsyncModule } from 'nativescript-async/angular';
3+
import { NativeScriptHttpAsyncModule } from 'nativescript-http-async/angular';
44
import { AppRoutingModule } from './app-routing.module';
55
import { AppComponent } from './app.component';
66
import { NativeScriptHttpClientModule } from 'nativescript-angular/http-client';
@@ -12,7 +12,7 @@ import { NativeScriptHttpClientModule } from 'nativescript-angular/http-client';
1212
imports: [
1313
NativeScriptModule,
1414
NativeScriptHttpClientModule,
15-
NativeScriptAsyncModule,
15+
NativeScriptHttpAsyncModule,
1616
AppRoutingModule
1717
],
1818
declarations: [

demo-angular/src/app/services/data.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ObservableArray } from 'tns-core-modules/data/observable-array';
55
import { from } from 'rxjs';
66
import { map, mergeMap , concatMap,switchMap} from 'rxjs/internal/operators';
77
import * as imageSrc from 'tns-core-modules/image-source';
8-
import { TNSXMLHttpRequest, FileManager } from 'nativescript-async';
8+
import { TNSXMLHttpRequest, FileManager } from 'nativescript-http-async';
99
import * as fs from 'tns-core-modules/file-system';
1010
import { releaseNativeObject } from 'tns-core-modules/utils/utils';
1111
declare var UIImageJPEGRepresentation, NSDataBase64EncodingOptions, android, java;

demo/app/home/home-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Async } from 'nativescript-async';
1+
import { Async } from 'nativescript-http-async';
22
console.log(new Async().message);
33
/*
44
In NativeScript, a file with the same name as an XML file is known as

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"license": "SEE LICENSE IN <your-license-filename>",
1313
"repository": "<fill-your-repository-here>",
1414
"dependencies": {
15-
"nativescript-async": "file:../src",
15+
"nativescript-http-async": "file:../src",
1616
"nativescript-theme-core": "~1.0.4",
1717
"tns-core-modules": "~5.4.0"
1818
},

src/angular/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ const BASE_PROVIDERS = [
1111
@NgModule({
1212
providers: BASE_PROVIDERS
1313
})
14-
export class NativeScriptAsyncModule {
14+
export class NativeScriptHttpAsyncModule {
1515
static forRoot(options: { configuredProviders?: Array<any>; debug?: boolean; }): ModuleWithProviders {
1616
if (options.debug) {
1717
TNSHttpDebugging.enabled = true;
1818
}
1919
return {
20-
ngModule: NativeScriptAsyncModule,
20+
ngModule: NativeScriptHttpAsyncModule,
2121
// Allow others to override if they need more control
2222
providers: [...BASE_PROVIDERS, ...(options.configuredProviders || [])]
2323
};
@@ -26,10 +26,10 @@ export class NativeScriptAsyncModule {
2626
constructor(
2727
@Optional()
2828
@SkipSelf()
29-
parentModule: NativeScriptAsyncModule
29+
parentModule: NativeScriptHttpAsyncModule
3030
) {
3131
if (parentModule) {
32-
throw new Error(`NativeScriptAsyncModule has already been loaded. Import NativeScriptAsyncModule in the AppModule only.`);
32+
throw new Error(`NativeScriptHttpAsyncModule has already been loaded. Import NativeScriptHttpAsyncModule in the AppModule only.`);
3333
}
3434
}
3535
}

src/http/http.ios.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,21 @@ class NSURLSessionTaskDelegateImpl extends NSObject
9898
data: NSData
9999
) {
100100
// const method = this._request.HTTPMethod.toLowerCase();
101-
if (this._onLoading && !this._loadingSent) {
102-
const lengthComputable = this._lastProgress.lengthComputable;
103-
this._onLoading({
104-
lengthComputable,
105-
loaded: this._data.length,
106-
total: this._lastProgress.total
107-
});
108-
this._loadingSent = true;
109-
}
110-
if (this._onProgress) {
111-
const lengthComputable = this._lastProgress.lengthComputable;
112-
this._onProgress({
113-
lengthComputable,
114-
loaded: this._data.length,
115-
total: this._lastProgress.total
116-
});
117-
}
118-
if (this._data) {
119-
this._data.appendData(data);
101+
if (data) {
102+
this._data.appendData(data);
103+
104+
const lastProgress: any = this._lastProgress || {
105+
lengthComputable: false,
106+
total: 0
107+
};
108+
lastProgress.loaded = this._data.length;
109+
if (this._onLoading && !this._loadingSent) {
110+
this._onLoading(lastProgress);
111+
this._loadingSent = true;
112+
}
113+
if (this._onProgress) {
114+
this._onProgress(lastProgress);
115+
}
120116
}
121117
}
122118

@@ -128,11 +124,10 @@ class NSURLSessionTaskDelegateImpl extends NSObject
128124
totalBytesExpectedToSend
129125
) {
130126
if (this._onLoading || this._onProgress) {
131-
const lengthComputable = totalBytesExpectedToSend > -1;
132127
this._lastProgress = {
133-
lengthComputable,
128+
lengthComputable: totalBytesExpectedToSend > -1,
134129
loaded: totalBytesSent,
135-
total: lengthComputable ? totalBytesExpectedToSend : 0
130+
total: totalBytesExpectedToSend > -1 ? totalBytesExpectedToSend : 0
136131
};
137132
if (this._onLoading && !this._loadingSent) {
138133
this._onLoading(this._lastProgress);

0 commit comments

Comments
 (0)