Skip to content

Commit 003f2aa

Browse files
committed
feat: add taro env
1 parent f7eed66 commit 003f2aa

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Diff for: packages/nerv-utils/src/env.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export const doc: Document = isBrowser ? document : fakeDoc
3333
export const UA = isBrowser && window.navigator.userAgent.toLowerCase()
3434

3535
export const isMacSafari = isBrowser && UA && window.navigator.platform &&
36-
/mac/i.test(navigator.platform) && /^((?!chrome|android).)*safari/i.test(UA)
36+
/mac/i.test(window.navigator.platform) && /^((?!chrome|android).)*safari/i.test(UA)
37+
38+
export const isTaro = isBrowser && !document.scripts
3739

3840
export const isIE9 = UA && UA.indexOf('msie 9.0') > 0
41+
3942
export const isiOS = (UA && /iphone|ipad|ipod|ios/.test(UA))

Diff for: packages/nerv/src/event.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isFunction, MapClass, doc, isiOS, isIE9 } from 'nerv-utils'
1+
import { isFunction, MapClass, doc, isiOS, isIE9, isTaro } from 'nerv-utils'
22
import { noop } from 'nerv-shared'
33

44
const ONINPUT = 'oninput'
@@ -94,7 +94,7 @@ export function attachEvent (
9494
return
9595
}
9696
let delegatedRoots = delegatedEvents.get(eventName)
97-
if (unbubbleEvents[eventName] === 1) {
97+
if (unbubbleEvents[eventName] === 1 || isTaro) {
9898
if (!delegatedRoots) {
9999
delegatedRoots = new MapClass()
100100
}
@@ -137,7 +137,7 @@ export function detachEvent (
137137
return
138138
}
139139
const delegatedRoots = delegatedEvents.get(eventName)
140-
if (unbubbleEvents[eventName] === 1 && delegatedRoots) {
140+
if ((unbubbleEvents[eventName] === 1 && delegatedRoots) || isTaro) {
141141
const event = delegatedRoots.get(domNode)
142142
if (event) {
143143
domNode.removeEventListener(parseEventName(eventName), event.event, false)

0 commit comments

Comments
 (0)