How to use the @tarojs/shared.ensure 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-runtime / src / dsl / vue.ts View on Github external
export function createVueApp (App: VueInstance) {
  let Vue
  // webpack 开发模式不会执行 tree-shaking,因此我们需要做此判断
  if (process.env.FRAMEWORK === 'vue') {
    const v = require('vue')
    Vue = v.default || v
  }

  ensure(!!Vue, '构建 Vue 项目请把 process.env.FRAMEWORK 设置为 \'vue\'')

  Vue.config.getTagNamespace = noop

  const elements: VNode[] = []
  const pages: Array<(h: Vue.CreateElement) => VNode> = []
  let appInstance: VueAppInstance

  const wrapper = new (Vue as VueConstructor)({
    render (h) {
      while (pages.length > 0) {
        const page = pages.pop()!
        elements.push(page(h))
      }

      return h(App.$options, { ref: 'app' }, elements.slice())
    },
github NervJS / taro / packages / taro-runtime / src / dsl / react.ts View on Github external
if (process.env.FRAMEWORK === 'nerv') {
    R = require('nervjs')
    ReactDOM = R
  }

  // 其它 react-like 框架走 react 模式,在 webpack.resolve.alias 设置 react/react-dom 到对应包
  if (process.env.FRAMEWORK === 'react') {
    R = require('react')
    ReactDOM = require('react-dom')
  }

  react = R

  PageContext = R.createContext('')

  ensure(!!ReactDOM, '构建 React/Nerv 项目请把 process.env.FRAMEWORK 设置为 \'react\'/\'nerv\' ')

  const ref = R.createRef()

  let wrapper: AppWrapper

  class AppWrapper extends R.Component {
    // run createElement() in a render function to make sure that owner is right
    private pages: Array<() => React.FunctionComponentElement> = []
    private elements: Array> = []

    public mount (component: React.FunctionComponent, id: string, cb: () => void) {
      const page = () => R.createElement(component, { key: id, tid: id })
      this.pages.push(page)
      this.forceUpdate(cb)
    }
github NervJS / taro / packages / taro-runtime / src / dsl / common.ts View on Github external
Current.app!.mount(component, id, () => {
        page = document.getElementById(id)
        instance = instances.get(id) || EMPTY_OBJ

        ensure(page !== null, '没有找到页面实例。')
        safeExecute('onLoad', options)
        page.ctx = this
        page.performUpdate(true)
      })
    },
github NervJS / taro / packages / taro-runtime / src / dom / node.ts View on Github external
protected findIndex (childeNodes: TaroNode[], refChild: TaroNode) {
    const index = childeNodes.indexOf(refChild)
    ensure(index !== -1, 'The node to be replaced is not a child of this node.')

    return index
  }
}