How to use the js-data.utils.resolve function in js-data

To help you get started, we’ve selected a few js-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 js-data / js-data-http / src / index.js View on Github external
DEL (url, config, opts) {
    let op
    config || (config = {})
    opts || (opts = {})
    config.url = url || config.url
    config.method = config.method || 'delete'

    // beforeDEL lifecycle hook
    op = opts.op = 'beforeDEL'
    return utils.resolve(this[op](url, config, opts))
      .then((_config) => {
        // Allow re-assignment from lifecycle hook
        config = _config === undefined ? config : _config
        op = opts.op = 'DEL'
        this.dbg(op, url, config, opts)
        return this.HTTP(config, opts)
      })
      .then((response) => {
        // afterDEL lifecycle hook
        op = opts.op = 'afterDEL'
        return utils.resolve(this[op](url, config, opts, response))
          .then((_response) => _response === undefined ? response : _response)
      })
  },
github js-data / js-data-http / src / index.js View on Github external
.then((response) => {
        // afterPUT lifecycle hook
        op = opts.op = 'afterPUT'
        return utils.resolve(this[op](url, data, config, opts, response))
          .then((_response) => _response === undefined ? response : _response)
      })
  },
github js-data / js-data-http / src / index.js View on Github external
}
        return utils.reject(data)
      }
    }

    if (!this.http) {
      if ((this.useFetch || opts.useFetch)) {
        if (!hasFetch) {
          throw new Error('Attempting to use window.fetch, but it is not available!')
        }
      } else {
        throw new Error('You have not configured this adapter with an http library!')
      }
    }

    return utils.resolve(this.beforeHTTP(config, opts))
      .then((_config) => {
        config = _config || config
        if (hasFetch && (this.useFetch || opts.useFetch || !this.http)) {
          return this.fetch(config, opts).then(logResponse, logResponse)
        }
        const httpConfig = utils.plainCopy(config)
        delete httpConfig.adapter
        return this.http(httpConfig).then(logResponse, logResponse)
          .catch((err) => this.responseError(err, config, opts))
      })
      .then((response) => {
        return utils.resolve(this.afterHTTP(config, opts, response))
          .then((_response) => _response === undefined ? response : _response)
      })
  },
github js-data / js-data-http / src / index.js View on Github external
.then((response) => {
        return utils.resolve(this.afterHTTP(config, opts, response))
          .then((_response) => _response === undefined ? response : _response)
      })
  },
github js-data / js-data-http / src / index.js View on Github external
utils.deepMixIn(config, _opts)
      config.method = config.method || 'GET'
      if (typeof _opts.getEndpoint === 'function') {
        config.url = _opts.getEndpoint(this, _opts)
      } else {
        let args = [
          _opts.basePath || this.basePath || adapter.basePath,
          adapter.getEndpoint(this, id, _opts)
        ]
        if (utils.isSorN(id)) {
          args.push(id)
        }
        args.push(opts.pathname || name)
        config.url = makePath.apply(null, args)
      }
      return utils.resolve(config)
        .then(_opts.request)
        .then((config) => adapter.HTTP(config))
        .then((data) => {
          if (data && data.config) {
            data.config.mapper = this.name
          }
          return data
        })
        .then(_opts.response, _opts.responseError)
    }
    return mapper
github js-data / js-data-examples / client / react / src / store.js View on Github external
getLoggedInUser () {
    if (this.loggedInUser) {
      return utils.resolve(this.loggedInUser)
    }
    return store.getAdapter('http').GET('/api/users/loggedInUser')
      .then((response) => {
        const user = this.loggedInUser = response.data
        if (user) {
          this.loggedInUser = store.add('user', user)
        }
        return this.loggedInUser
      })
  }
})