Skip to content

Commit

Permalink
A safer way to detect Promise.
Browse files Browse the repository at this point in the history
  • Loading branch information
wxsms committed Nov 28, 2017
1 parent 8912ae8 commit efd7794
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/services/messagebox/messageBox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {TYPES} from './constants'
import {removeFromDom} from '@src/utils/domUtils'
import {isFunction, isExist, isString} from '@src/utils/objectUtils'
import {isFunction, isExist, isString, isPromiseSupported} from '@src/utils/objectUtils'
import MessageBox from './MessageBox.vue'
import Vue from 'vue'

Expand Down Expand Up @@ -61,7 +61,7 @@ const init = (type, options, cb, resolve = null, reject = null) => {
}

const initModal = (type, options = {}, cb) => {
if (isExist(window.Promise)) {
if (isPromiseSupported()) {
return new Promise((resolve, reject) => {
init(type, options, cb, resolve, reject)
})
Expand Down
4 changes: 2 additions & 2 deletions src/services/notification/notification.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {removeFromDom} from '@src/utils/domUtils'
import {spliceIfExist} from '@src/utils/arrayUtils'
import {isFunction, isExist, isString} from '@src/utils/objectUtils'
import {isFunction, isExist, isString, isPromiseSupported} from '@src/utils/objectUtils'
import Notification from './Notification.vue'
import {PLACEMENTS} from './constants'
import Vue from 'vue'
Expand Down Expand Up @@ -58,7 +58,7 @@ const notify = (options = {}, cb) => {
if (!isExist(options.placement)) {
options.placement = PLACEMENTS.TOP_RIGHT
}
if (isExist(window.Promise)) {
if (isPromiseSupported()) {
return new Promise((resolve, reject) => {
init(options, cb, resolve, reject)
})
Expand Down
4 changes: 4 additions & 0 deletions src/utils/objectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ export function isString (obj) {
export function isBoolean (obj) {
return typeof obj === 'boolean'
}

export function isPromiseSupported () {
return typeof window !== 'undefined' && isExist(window.Promise)
}

0 comments on commit efd7794

Please sign in to comment.