LP#626157 ang2 misc tidying
authorBill Erickson <berickxx@gmail.com>
Wed, 27 Dec 2017 17:41:55 +0000 (12:41 -0500)
committerBill Erickson <berickxx@gmail.com>
Wed, 27 Dec 2017 17:41:55 +0000 (12:41 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/eg2-src/src/app/core/idl.ts
Open-ILS/eg2-src/src/app/core/net.ts
Open-ILS/eg2-src/src/app/core/pcrud.ts
Open-ILS/eg2-src/src/app/core/store.ts

index 8f46933..fdbd111 100644 (file)
@@ -1,21 +1,15 @@
-import { Injectable } from '@angular/core';
+import {Injectable} from '@angular/core';
 
 // Added globally by /IDL2js
 declare var _preload_fieldmapper_IDL: Object;
 
 /**
- * NOTE: To achieve full type strictness and avoid compile warnings,
- * we would likely have to pre-compile the IDL down to a .ts file with all 
- * of the IDL class and field definitions.
- */
-
-/**
  * Every IDL object class implements this interface.
  */
 export interface EgIdlObject {
     a: any[];
-    classname: String;
-    _isfieldmapper: Boolean;
+    classname: string;
+    _isfieldmapper: boolean;
     // Dynamically appended functions from the IDL.
     [fields: string]: any;
 }
index 502ffbf..f6ec6b2 100644 (file)
@@ -2,7 +2,7 @@
  * 
  * constructor(private net : EgNetService) {
  *   ...
- *   egNet.request(service, method, param1 [, param2, ...])
+ *   this.net.request(service, method, param1 [, param2, ...])
  *     .subscribe(
  *       (res) => console.log('received one resopnse: ' + res),
  *       (err) => console.error('recived request error: ' + err),
  *     )
  *   );
  *   ...
+ *
+ *  // Example translating a net request into a promise.
+ *  this.net.request(service, method, param1)
+ *  .toPromise().then(result => console.log(result));
+ *
  * }
  *
- * Each response is relayed via Observable onNext().  The interface is 
+ * Each response is relayed via Observable.next().  The interface is 
  * the same for streaming and atomic requests.
  */
 import {Injectable, EventEmitter} from '@angular/core';
@@ -24,11 +29,11 @@ import {EgEventService, EgEvent} from './event';
 declare var OpenSRF, OSRF_TRANSPORT_TYPE_WS;
 
 export class EgNetRequest {
-    service    : String;
-    method     : String;
+    service    : string;
+    method     : string;
     params     : any[];
     observer   : Observer<any>;
-    superseded : Boolean = false;
+    superseded : boolean = false;
     // If set, this will be used instead of a one-off OpenSRF.ClientSession.
     session?   : any;
     // True if we're using a single-use local session
@@ -39,7 +44,7 @@ export class EgNetRequest {
     // event will be available here.
     evt: EgEvent;
 
-    constructor(service: String, method: String, params: any[], session?: any) {
+    constructor(service: string, method: string, params: any[], session?: any) {
         this.service = service;
         this.method = method;
         this.params = params;
@@ -80,17 +85,18 @@ export class EgNetService {
     }
 
     // Standard request call -- Variadic params version
-    request(service: String, method: String, ...params: any[]): Observable<any> {
+    request(service: string, method: string, ...params: any[]): Observable<any> {
         return this.requestWithParamList(service, method, params);
     }
 
     // Array params version
-    requestWithParamList(service: String, 
-        method: String, params: any[]): Observable<any> {
+    requestWithParamList(service: string, 
+        method: string, params: any[]): Observable<any> {
         return this.requestCompiled(
             new EgNetRequest(service, method, params));
     }
 
+    // Request with pre-compiled EgNetRequest
     requestCompiled(request: EgNetRequest): Observable<any> {
         return Observable.create(
             observer => {
@@ -100,13 +106,13 @@ export class EgNetService {
         );
     }
 
-    // Version with pre-compiled EgNetRequest object
+    // Send the compiled request to the server via WebSockets
     sendCompiledRequest(request: EgNetRequest): void {
         OpenSRF.Session.transport = OSRF_TRANSPORT_TYPE_WS;
         console.debug(`EgNet: request ${request.method}`);
 
         request.session.request({
-            async  : true,
+            async  : true, // WS only operates in async mode
             method : request.method,
             params : request.params,
             oncomplete : () => {
index 643a515..e8a3ec5 100644 (file)
@@ -4,7 +4,7 @@ import {EgIdlService, EgIdlObject} from './idl';
 import {EgNetService, EgNetRequest} from './net';
 import {EgAuthService} from './auth';
 
-// Used for debugging.
+// Externally defined.  Used here for debugging.
 declare var js2JSON: (jsThing:any) => string;
 declare var OpenSRF: any; // creating sessions
 
index fcb83c6..2b3522b 100644 (file)
@@ -1,9 +1,9 @@
 /**
  * Store and retrieve data from various sources.
  */
-import { Injectable } from '@angular/core';
-import { Observable } from 'rxjs/Rx';
-import { CookieService } from 'ngx-cookie';
+import {Injectable} from '@angular/core';
+import {Observable} from 'rxjs/Rx';
+import {CookieService} from 'ngx-cookie';
 
 @Injectable()
 export class EgStoreService {