How to use the native-promise-only function in native-promise-only

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
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 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 / Webform.js View on Github external
this.formReadyReject = reject;
    });

    /**
     * Promise that executes when the submission is ready and rendered.
     * @type {Promise}
     *
     * @example
     * import Webform from 'formiojs/Webform';
     * let form = new Webform(document.getElementById('formio'));
     * form.submissionReady.then(() => {
     *   console.log('The submission is ready!');
     * });
     * form.src = 'https://examples.form.io/example/submission/234234234234234243';
     */
    this.submissionReady = new NativePromise((resolve, reject) => {
      /**
       * Called when the formReady state of this form has been resolved.
       *
       * @type {function}
       */
      this.submissionReadyResolve = resolve;

      /**
       * Called when this form could not load and is rejected.
       *
       * @type {function}
       */
      this.submissionReadyReject = reject;
    });

    this.shortcuts = [];
github formio / formio.js / src / displays / wizard / Wizard.js View on Github external
beforePage(next) {
    return new NativePromise((resolve, reject) => {
      this.hook(next ? 'beforeNext' : 'beforePrev', this.currentPage, this.submission, (err) => {
        if (err) {
          this.showErrors(err, true);
          reject(err);
        }

        const form = this.currentPage;
        if (form) {
          form.beforePage(next).then(resolve).catch(reject);
        }
        else {
          resolve();
        }
      });
    });
  }
github formio / formio.js / src / PDF.js View on Github external
getSubmission() {
    return new NativePromise((resolve) => {
      this.once('iframe-submission', resolve);
      this.postMessage({ name: 'getSubmission' });
    });
  }
github formio / formio.js / src / components / tagpad / Tagpad.js View on Github external
constructor(...args) {
    super(...args);
    this.type = 'tagpad';
    this.dots = [];
    _.defaults(this.component, {
      dotSize: 10,
      dotStrokeSize: 2,
      dotStrokeColor: '#333',
      dotFillColor: '#ccc'
    });
    //init background ready promise
    const backgroundReadyPromise = new NativePromise((resolve, reject) => {
      this.backgroundReady = { resolve, reject };
    });
    this.backgroundReady.promise = backgroundReadyPromise;
    //init dimensions multiplier
    this.dimensionsMultiplier = 1;
  }

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