Sha256: 78ff6c04689bf3380b8b530ded9e187f4e0841915fd26f32a48cf638d01f76d3

Contents?: true

Size: 573 Bytes

Versions: 35

Compression:

Stored size: 573 Bytes

Contents

function promiseState(promise) {
  var uniqueValue = window['Symbol'] ? Symbol('unique') : Math.random().toString(36)

  function notifyPendingOrResolved(value) {
    if (value === uniqueValue) {
      return Promise.resolve({ state: 'pending' })
    } else {
      return Promise.resolve({ state: 'fulfilled', value: value })
    }
  }

  function notifyRejected(reason) {
    return Promise.resolve({ state: 'rejected', value: reason })
  }

  var race = [promise, Promise.resolve(uniqueValue)]
  return Promise.race(race).then(notifyPendingOrResolved, notifyRejected)
}

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
unpoly-rails-1.0.3 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-1.0.1 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-1.0.0 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.62.1 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.62.0 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.61.1 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.61.0 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.60.3 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.60.2 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.60.1 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.60.0 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.57.0 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.56.7 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.56.6 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.56.5 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.56.4 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.56.3 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.56.2 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.56.1 spec_app/spec/javascripts/helpers/promise_state.js
unpoly-rails-0.56.0 spec_app/spec/javascripts/helpers/promise_state.js