How to use the kinvey-nativescript-sdk.DataStore function in kinvey-nativescript-sdk

To help you get started, we’ve selected a few kinvey-nativescript-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NativeScript / nativescript-app-templates / packages / template-master-detail-kinvey / app / cars / shared / car-service.js View on Github external
function CarService() {
    if (CarService._instance) {
        throw new Error("Use CarService.getInstance() instead of new.");
    }

    this._cars = [];
    this._carsStore = Kinvey.DataStore.collection("cars");

    CarService._instance = this;

    this.load = function () {
        return this._login().then(() => this._carsStore.sync()).then(() => {
            const sortByNameQuery = new Kinvey.Query();
            sortByNameQuery.ascending("name");
            const stream = this._carsStore.find(sortByNameQuery);

            return stream.toPromise();
        }).then((data) => {
            this._allCars = [];
            data.forEach((carData) => {
                carData.id = carData._id;
                const car = new Car(carData);