Skip to content

Commit

Permalink
feat: add taro env
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Sep 25, 2019
1 parent f7eed66 commit 003f2aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/nerv-utils/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const doc: Document = isBrowser ? document : fakeDoc
export const UA = isBrowser && window.navigator.userAgent.toLowerCase()

export const isMacSafari = isBrowser && UA && window.navigator.platform &&
/mac/i.test(navigator.platform) && /^((?!chrome|android).)*safari/i.test(UA)
/mac/i.test(window.navigator.platform) && /^((?!chrome|android).)*safari/i.test(UA)

export const isTaro = isBrowser && !document.scripts

export const isIE9 = UA && UA.indexOf('msie 9.0') > 0

export const isiOS = (UA && /iphone|ipad|ipod|ios/.test(UA))
6 changes: 3 additions & 3 deletions packages/nerv/src/event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isFunction, MapClass, doc, isiOS, isIE9 } from 'nerv-utils'
import { isFunction, MapClass, doc, isiOS, isIE9, isTaro } from 'nerv-utils'
import { noop } from 'nerv-shared'

const ONINPUT = 'oninput'
Expand Down Expand Up @@ -94,7 +94,7 @@ export function attachEvent (
return
}
let delegatedRoots = delegatedEvents.get(eventName)
if (unbubbleEvents[eventName] === 1) {
if (unbubbleEvents[eventName] === 1 || isTaro) {
if (!delegatedRoots) {
delegatedRoots = new MapClass()
}
Expand Down Expand Up @@ -137,7 +137,7 @@ export function detachEvent (
return
}
const delegatedRoots = delegatedEvents.get(eventName)
if (unbubbleEvents[eventName] === 1 && delegatedRoots) {
if ((unbubbleEvents[eventName] === 1 && delegatedRoots) || isTaro) {
const event = delegatedRoots.get(domNode)
if (event) {
domNode.removeEventListener(parseEventName(eventName), event.event, false)
Expand Down

0 comments on commit 003f2aa

Please sign in to comment.