Use JSDO and the Data Source Modules in an existing NativeScript application
- Last Updated: July 11, 2019
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
Use JSDO and the Data Source Modules in an existing NativeScript application
Setup:
This setup uses the NativeScript Cars app to demonstrate this functionality.
- Run the following command to create the master template:
tns create my-master-detail-ng --template tns-template-master-detail-ng. - Use the following command to access the master template:
cd my-master-detail-ng. - Use the following command to set up your desired operating system:
tns run <android/ios>. - Install the
@progress/jsdo-nativescriptand@progress/jsdo-corenpm packages in your NativeScript project by running the following command:npm install @progress/jsdo-nativescript @progress/jsdo-core. - Make the following changes to the Cars app to use the JSDO and
the Data Source modules:
- In
src/app/cars/shared/car.service.ts:- Add the following import
statements:
import { progress } from "@progress/jsdo-core"; import { DataSource, DataSourceOptions, DataResult } from "@progress/jsdo-nativescript"; import { Observable, from } from "rxjs"; import { catchError } from "rxjs/operators"; - Find the following lines of
code:
load(): Observable<any> { return new Observable((observer: any) => { const path = "cars"; const onValueEvent = (snapshot: any) => { this._ngZone.run(() => { const results = this.handleSnapshot(snapshot.value); observer.next(results); }); }; firebase.addValueEventListener(onValueEvent, `/${path}`); }).pipe(catchError(this.handleErrors)); } - Replace the above code with the
following:
private dataSource: DataSource; createSession(successFn, errorFn): void { const serviceURI = "https://oemobiledemo.progress.com/OEMobileDemoServices"; progress.data.getSession({ serviceURI, catalogURI: serviceURI + "/static/SportsService.json", authenticationModel: "anonymous" }).then((object) => { this.dataSource = new DataSource({ jsdo: new progress.data.JSDO({ name: "Customer" }) }); successFn(); }, () => errorFn()); } load(): Observable<any> { const promise = new Promise((resolve, reject) => { this.createSession(() => { this.dataSource.read().subscribe((myData: DataResult) => { resolve(myData.data); }); }, (error) => { const message = (error && error.message) ? error.message : "Error reading records."; reject(new Error(message)); }); }); return from(promise).pipe(catchError(this.handleErrors)); }
- Add the following import
statements:
- In
src/app/cars/car-list.component.html, changecar.nametocar.Name:<Label [text]="car.Name" class="text-primary font-weight-bold"></Label>
- In
As a result of these changes, when you launch the Cars app on the emulator, you will see that the app is connected to OEMobileDemoServices and that it displays customer names instead of car names.