How to use @tarojs/mobx-common - 10 common examples

To help you get started, we’ve selected a few @tarojs/mobx-common 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-mobx-h5 / src / observer.js View on Github external
this.componentWillReact && this.componentWillReact()
        this.forceUpdate()
      })
    }

    let result
    let exception
    this._reaction.track(() => {
      try {
        result = originRender.call(this, null, null, args[2])
      } catch (e) {
        exception = e
      }
    })
    if (exception) {
      errorsReporter.emit(exception)
      throw exception
    }
    return result
  }
github NervJS / taro / packages / taro-mobx / src / observer.js View on Github external
target._createData = function (...args) {
    let result
    let exception
    if (this._reaction instanceof Reaction) {
      this._reaction.track(() => {
        try {
          result = originRender.call(this, null, null, args[2])
        } catch (e) {
          exception = e
        }
      })
    } else {
      result = originRender.call(this, null, null, args[2])
    }
    if (exception) {
      errorsReporter.emit(exception)
      throw exception
    }
    return result
  }
github NervJS / taro / packages / taro-mobx-h5 / src / observer.js View on Github external
export function observer (component) {
  if (isUsingStaticRendering()) {
    return component
  }

  if (component.isMobxInjector === true) {
    console.warn(
      "Mobx observer: You are trying to use 'observer' on a component that already has 'inject'. Please apply 'observer' before applying 'inject'"
    )
  }

  const target = component.prototype

  const originComponentWillUnmount = target.componentWillUnmount
  target.componentWillUnmount = function () {
    if (this._reaction) {
      this._reaction.dispose()
    }
github NervJS / taro / packages / taro-mobx / src / observer.js View on Github external
export function observer (component) {
  if (isUsingStaticRendering()) {
    return component
  }

  if (component.isMobxInjector === true) {
    console.warn(
      "Mobx observer: You are trying to use 'observer' on a component that already has 'inject'. Please apply 'observer' before applying 'inject'"
    )
  }

  const target = component.prototype
  const originConstructor = target._constructor
  target._constructor = function () {
    if (this.$scope) {
      const initialName = this.displayName || this.name
      this._reaction = new Reaction(`${initialName}_${Date.now()}`, () => {
        this.componentWillReact && this.componentWillReact()
github NervJS / taro / packages / taro-mobx-h5 / src / inject.js View on Github external
render () {
      const originProps = mapStoreToProps(grabStoresFn, this.props)
      return createElement(sourceComponent, {
        ...originProps,
        ref: ref => {
          originProps.ref && originProps.ref(ref)
          if (ref) {
            this.__observeInstance = ref
          }
        }
      })
    }
github NervJS / taro / packages / taro-mobx-rn / src / inject.js View on Github external
render () {
      const originProps = mapStoreToProps(grabStoresFn, this.props)
      return createElement(sourceComponent, {
        ...originProps,
        ref: ref => {
          originProps.ref && originProps.ref(ref)
          if (ref) {
            this.__observeInstance = ref
          }
        }
      })
    }
github NervJS / taro / packages / taro-mobx / src / inject.js View on Github external
constructor (props, isPage) {
      super(Object.assign(...arguments, mapStoreToProps(grabStoresFn, props)), isPage)
    }
github NervJS / taro / packages / taro-mobx / src / inject.js View on Github external
_constructor () {
      Object.assign(this.props, mapStoreToProps(grabStoresFn, this.props))
      super._constructor && super._constructor(this.props)
    }
  }
github NervJS / taro / packages / taro-mobx-rn / src / inject.js View on Github external
function createStoreInjector (grabStoresFn, injectNames, sourceComponent) {
  class Injector extends Component {
    static isMobxInjector = true
    static config = sourceComponent.config || {}
    static displayName = getInjectName(sourceComponent, injectNames)
    __observeInstance

    render () {
      const originProps = mapStoreToProps(grabStoresFn, this.props)
      return createElement(sourceComponent, {
        ...originProps,
        ref: ref => {
          originProps.ref && originProps.ref(ref)
          if (ref) {
            this.__observeInstance = ref
          }
        }
      })
    }

    componentDidShow () {
github NervJS / taro / packages / taro-mobx-h5 / src / inject.js View on Github external
function createStoreInjector (grabStoresFn, injectNames, sourceComponent) {
  class Injector extends Component {
    static isMobxInjector = true
    static config = sourceComponent.config || {}
    static displayName = getInjectName(sourceComponent, injectNames)
    __observeInstance

    render () {
      const originProps = mapStoreToProps(grabStoresFn, this.props)
      return createElement(sourceComponent, {
        ...originProps,
        ref: ref => {
          originProps.ref && originProps.ref(ref)
          if (ref) {
            this.__observeInstance = ref
          }
        }
      })
    }

    componentDidShow () {