How to use native-promise-only - 10 common examples

To help you get started, we’ve selected a few native-promise-only 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 formio / formio.js / src / Webform.js View on Github external
setForm(form) {
    // Create the form.
    this._form = form;

    // Allow the form to provide component overrides.
    if (form && form.settings && form.settings.components) {
      this.options.components = form.settings.components;
    }

    this.initialized = false;
    const rebuild = this.rebuild() || NativePromise.resolve();
    return rebuild.then(() => {
      this.emit('formLoad', form);
      this.triggerRecaptcha();
      // Make sure to trigger onChange after a render event occurs to speed up form rendering.
      setTimeout(() => {
        this.onChange();
        this.formReadyResolve();
      }, 0);
      return this.formReady;
    });
  }
github formio / formio.js / src / Webform.js View on Github external
localize() {
    if (i18next.initialized) {
      return Promise.resolve(i18next);
    }
    i18next.initialized = true;
    return new Promise((resolve, reject) => {
      try {
        i18next.init(this.options.i18n, (err) => {
          // Get language but remove any ;q=1 that might exist on it.
          this.options.language = i18next.language.split(';')[0];
          if (err) {
            return reject(err);
          }
          resolve(i18next);
        });
      }
      catch (err) {
        return reject(err);
      }
    });
  }
github intervalia / gulp-component-assembler / src / watcher.js View on Github external
watchedFiles[file].forEach(function(assembly) {
      promises.push(new Promise(function(resolve, reject) {
        touch(assembly, function() {
          resolve();
        });
      }));
    });

    // Remove references to the file but don't unwatch it
    delete watchedFiles[file];
  }

  // Add events always fire a change event for the same file, so we'll ignore add events
  if (event !== 'add') {
    // The file is done touching any parent files
    Promise.all(promises).then(function() {
      touchedFiles++;

      // fire the event once all filesToTouch and have been touched
      if (filesToTouch > 0 && touchedFiles === filesToTouch) {

        filesToTouch = 1;  // always count the staring file
        touchedFiles = 0;
        touchEvents.emit('allTouched');
      }
    });
  }
}
github formio / angular-formio / src / modules / resource / resource.service.ts View on Github external
property: 'submission',
                            value: this.resource
                        });

                        return {
                            name: parent,
                            resource: resource
                        };
                    }
                    return null;
                }));
            }
        });

        // When all the parents have loaded, emit that to the onParents emitter.
        Promise.all(parentsLoaded).then((parents: any) => this.onParents.emit(parents));
    }
github formio / formio.js / src / components / base / Base.js View on Github external
BaseComponent.requireLibrary = function(name, property, src, polling) {
  if (!BaseComponent.externalLibraries.hasOwnProperty(name)) {
    BaseComponent.externalLibraries[name] = {};
    BaseComponent.externalLibraries[name].ready = new Promise((resolve, reject) => {
      BaseComponent.externalLibraries[name].resolve = resolve;
      BaseComponent.externalLibraries[name].reject = reject;
    });

    if (!polling && !window[name + 'Callback']) {
      window[name + 'Callback'] = function() {
        this.resolve();
      }.bind(BaseComponent.externalLibraries[name]);
    }

    // See if the plugin already exists.
    let plugin = _get(window, property);
    if (plugin) {
      BaseComponent.externalLibraries[name].resolve(plugin);
    }
    else {
github formio / formio.js / src / validator / Validator.js View on Github external
// Skip if setting is falsy
          if (!boolValue(setting)) {
            return true;
          }

          // Skip if value is empty
          if (!value || _.isEmpty(value)) {
            return true;
          }

          // Skip if we don't have a database connection
          if (!config.db) {
            return true;
          }

          return new NativePromise(resolve => {
            const form = config.form;
            const submission = config.submission;
            const path = `data.${component.path}`;

            // Build the query
            const query = { form: form._id };

            if (_.isString(value)) {
              query[path] = {
                $regex: new RegExp(`^${escapeRegExCharacters(value)}$`),
                $options: 'i'
              };
            }
            // FOR-213 - Pluck the unique location id
            else if (_.isPlainObject(value) && value.hasOwnProperty('address_components') && value.hasOwnProperty('place_id')) {
              query[`${path}.place_id`] = {
github vimeo / player.js / src / player.js View on Github external
}

        // iframe url is not a Vimeo url
        if (element.nodeName === 'IFRAME' && !isVimeoUrl(element.getAttribute('src') || '')) {
            throw new Error('The player element passed isn’t a Vimeo embed.');
        }

        // If there is already a player object in the map, return that
        if (playerMap.has(element)) {
            return playerMap.get(element);
        }

        this.element = element;
        this.origin = '*';

        const readyPromise = new Promise((resolve, reject) => {
            const onMessage = (event) => {
                if (!isVimeoUrl(event.origin) || this.element.contentWindow !== event.source) {
                    return;
                }

                if (this.origin === '*') {
                    this.origin = event.origin;
                }

                const data = parseMessageData(event.data);
                const isError = data && data.event === 'error';
                const isReadyError = isError && data.data && data.data.method === 'ready';

                if (isReadyError) {
                    const error = new Error(data.data.message);
                    error.name = data.data.name;
github formio / formio.js / src / validator / rules / Unique.js View on Github external
check(value) {
    // Skip if value is empty
    if (!value || _.isEmpty(value)) {
      return true;
    }

    // Skip if we don't have a database connection
    if (!this.config.db) {
      return true;
    }

    return new NativePromise(resolve => {
      const form = this.config.form;
      const submission = this.config.submission;
      const path = `data.${this.component.path}`;

      // Build the query
      const query = { form: form._id };

      if (_.isString(value)) {
        query[path] = {
          $regex: new RegExp(`^${escapeRegExCharacters(value)}$`),
          $options: 'i'
        };
      }
      // FOR-213 - Pluck the unique location id
      else if (_.isPlainObject(value) && value.hasOwnProperty('address_components') && value.hasOwnProperty('place_id')) {
        query[`${path}.place_id`] = {
github formio / formio.js / src / Formio.js View on Github external
loadFormRevision(vid, query, opts) {
    if (!this.formUrl && !this.vUrl) {
      return NativePromise.reject('No form url set.');
    }

    // Set the version url if not set.
    if (vid && !this.vUrl) {
      this.vId = vid;
      this.vUrl = `${this.formUrl}/v/${vid}`;
    }

    // If they specified a revision form, load the revised form components.
    if (query && isObject(query)) {
      query = Formio.serialize(query.params);
    }
    if (query) {
      query = this.query ? (`${this.query}&${query}`) : (`?${query}`);
    }
    else {
github formio / formio.js / src / Formio.js View on Github external
static ssoInit(type, options) {
    switch (type) {
      case 'saml':
        return Formio.samlInit(options);
      case 'okta':
        return Formio.oktaInit(options);
      default:
        console.warn('Unknown SSO type');
        return NativePromise.reject('Unknown SSO type');
    }
  }

native-promise-only

Native Promise Only: A polyfill for native ES6 Promises **only**, nothing else.

MIT
Latest version published 9 years ago

Package Health Score

55 / 100
Full package analysis