How to use the @orbit/data.globals function in @orbit/data

To help you get started, we’ve selected a few @orbit/data 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 orbitjs / orbit / packages / @orbit / indexeddb / src / indexeddb-cache.ts View on Github external
return new Promise((resolve, reject) => {
      let request = Orbit.globals.indexedDB.deleteDatabase(this.dbName);

      request.onerror = (/* event */) => {
        // console.error('error deleting indexedDB', this.dbName);
        reject(request.error);
      };

      request.onsuccess = (/* event */) => {
        // console.log('success deleting indexedDB', this.dbName);
        resolve();
      };
    });
  }
github orbitjs / orbit / packages / @orbit / indexeddb / src / indexeddb-cache.ts View on Github external
return new Promise((resolve, reject) => {
      if (this._db) {
        resolve(this._db);
      } else {
        let request = Orbit.globals.indexedDB.open(this.dbName, this.dbVersion);

        request.onerror = (/* event */) => {
          // console.error('error opening indexedDB', this.dbName);
          reject(request.error);
        };

        request.onsuccess = (/* event */) => {
          // console.log('success opening indexedDB', this.dbName);
          const db = (this._db = request.result);
          resolve(db);
        };

        request.onupgradeneeded = (event: any) => {
          // console.log('indexedDB upgrade needed');
          const db = (this._db = event.target.result);
          if (event && event.oldVersion > 0) {
github orbitjs / orbit / packages / @orbit / jsonapi / src / jsonapi-request-processor.ts View on Github external
fetch(url: string, customSettings?: FetchSettings): Promise {
    let settings = this.initFetchSettings(customSettings);

    let fullUrl = url;
    if (settings.params) {
      fullUrl = this.urlBuilder.appendQueryParams(fullUrl, settings.params);
      delete settings.params;
    }

    let fetchFn = (Orbit as any).fetch || Orbit.globals.fetch;

    // console.log('fetch', fullUrl, settings, 'polyfill', fetchFn.polyfill);

    if (settings.timeout) {
      let timeout = settings.timeout;
      delete settings.timeout;

      return new Promise((resolve, reject) => {
        let timedOut: boolean;

        let timer = Orbit.globals.setTimeout(() => {
          timedOut = true;
          reject(new NetworkError(`No fetch response within ${timeout}ms.`));
        }, timeout);

        fetchFn(fullUrl, settings)
github orbitjs / orbit / packages / @orbit / local-storage / src / lib / pull-operators.ts View on Github external
const operations = [];

    const typeFilter = expression.type;

    for (let key in Orbit.globals.localStorage) {
      if (key.indexOf(source.namespace + source.delimiter) === 0) {
        let typesMatch = isNone(typeFilter);

        if (!typesMatch) {
          let fragments = key.split(source.delimiter);
          let type = fragments[1];
          typesMatch = (typeFilter === type);
        }

        if (typesMatch) {
          let record = JSON.parse(Orbit.globals.localStorage.getItem(key));

          if (source.keyMap) {
            source.keyMap.pushRecord(record);
          }

          operations.push({
            op: 'addRecord',
            record
          });
        }
      }
    }

    return Orbit.Promise.resolve([buildTransform(operations)]);
  },
github orbitjs / orbit / packages / @orbit / local-storage / src / lib / pull-operators.ts View on Github external
findRecords(source: LocalStorageSource, expression: FindRecords): Promise {
    const operations = [];

    const typeFilter = expression.type;

    for (let key in Orbit.globals.localStorage) {
      if (key.indexOf(source.namespace + source.delimiter) === 0) {
        let typesMatch = isNone(typeFilter);

        if (!typesMatch) {
          let fragments = key.split(source.delimiter);
          let type = fragments[1];
          typesMatch = (typeFilter === type);
        }

        if (typesMatch) {
          let record = JSON.parse(Orbit.globals.localStorage.getItem(key));

          if (source.keyMap) {
            source.keyMap.pushRecord(record);
          }
github orbitjs / orbit / packages / @orbit / jsonapi / src / jsonapi-request-processor.ts View on Github external
.then((response: any) => {
            Orbit.globals.clearTimeout(timer);

            if (!timedOut) {
              return this.handleFetchResponse(response);
            }
          })
          .then(resolve, reject);
github orbitjs / orbit / packages / @orbit / local-storage / src / local-storage-cache.ts View on Github external
getRecordSync(identity: RecordIdentity): Record | undefined {
    const key = this.getKeyForRecord(identity);
    const item: string | undefined = Orbit.globals.localStorage.getItem(key);

    if (item) {
      const record: Record = JSON.parse(item);

      if (this._keyMap) {
        this._keyMap.pushRecord(record);
      }

      return record;
    }

    return undefined;
  }
github orbitjs / orbit / packages / @orbit / local-storage / src / local-storage-cache.ts View on Github external
removeRecordSync(recordIdentity: RecordIdentity): Record {
    const record = this.getRecordSync(recordIdentity);
    if (record) {
      const key = this.getKeyForRecord(record);
      Orbit.globals.localStorage.removeItem(key);
      return record;
    } else {
      return null;
    }
  }