How to use the @tarojs/shared.isFunction function in @tarojs/shared

To help you get started, we’ve selected a few @tarojs/shared 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 NervJS / taro / packages / taro-react / src / props.ts View on Github external
}
        }
      }

      if (isObject(value)) {
        for (const i in value) {
          if (!oldValue || value[i] !== (oldValue as StyleValue)[i]) {
            setStyle(style, i, value[i])
          }
        }
      }
    }
  } else if (isEventName(name)) {
    setEvent(dom, name, value, oldValue)
  } else if (
    !isFunction(value) &&
    name !== 'dangerouslySetInnerHTML' // TODO: 实现 innerHTML
  ) {
    if (value == null) {
      dom.removeAttribute(name)
    } else {
      dom.setAttribute(name, value as string)
    }
  }
}
github NervJS / taro / packages / taro-runtime / src / dom / root.ts View on Github external
if (path.endsWith(Shortcuts.Childnodes)) {
          resetPaths.add(path)
        }
        data[path] = value
      }

      for (const path in data) {
        resetPaths.forEach(p => {
          // 已经重置了数组,就不需要分别再设置了
          if (path.includes(p) && path !== p) {
            delete data[path]
          }
        })

        const value = data[path]
        if (isFunction(value)) {
          data[path] = value()
        }
      }

      ctx.setData(data, () => {
        this.pendingUpdate = false
      })
    }, 1)
  }
github NervJS / taro / packages / taro-runtime / src / dsl / vue.ts View on Github external
onShow (options: unknown) {
      if (appInstance != null && isFunction(appInstance.$options.onShow)) {
        appInstance.$options.onShow.call(appInstance, options)
      }
    }
github NervJS / taro / packages / taro-runtime / src / dsl / vue.ts View on Github external
onHide (options: unknown) {
      if (appInstance != null && isFunction(appInstance.$options.onHide)) {
        appInstance.$options.onHide.call(appInstance, options)
      }
    }
github NervJS / taro / packages / taro-runtime / src / dsl / react.ts View on Github external
onHide (options: unknown) {
      const app = ref.current
      if (app != null && isFunction(app.componentDidHide)) {
        app.componentDidHide(options)
      }
    }
github NervJS / taro / packages / taro-react / src / props.ts View on Github external
function setEvent (dom: TaroElement, name: string, value: unknown, oldValue?: unknown) {
  const isCapture = name.endsWith('Capture')
  let eventName = name.toLowerCase().slice(2)
  if (isCapture) {
    eventName = eventName.slice(0, -7)
  }

  if (eventName === 'click') {
    eventName = 'tap'
  }

  if (isFunction(value)) {
    if (!oldValue) {
      dom.addEventListener(eventName, eventProxy, isCapture)
    }
    let events = listeners[dom.uid]
    if (!events) {
      events = listeners[dom.uid] = {}
    }
    events[eventName] = value
  } else {
    dom.removeEventListener(eventName, eventProxy)
    const events = listeners[dom.uid]
    delete events[eventName]
  }
}
github NervJS / taro / packages / taro-runtime / src / dsl / react.ts View on Github external
onShow (options: unknown) {
      const app = ref.current
      if (app != null && isFunction(app.componentDidShow)) {
        app.componentDidShow(options)
      }
    }