Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义组件Component()能通过connect绑定数据和动作吗? #18

Open
mingenesis opened this issue Mar 16, 2018 · 2 comments
Open

Comments

@mingenesis
Copy link

No description provided.

@liang121
Copy link

liang121 commented Jul 4, 2018

看了下源码,貌似不能

@libaoxu
Copy link

libaoxu commented Mar 25, 2019

可以修改的
修改源码 connect.js对Component支持

修改内容

    const {
      onLoad: _onLoad,
      onUnload: _onUnload,
      ready: _ready,
      detached: _detached,
    } = pageConfig

    function onLoad(options) {
      this.store = app.store;
      if (!this.store) {
        warning("Store对象不存在!")
      }
      if(shouldSubscribe){
        this.unsubscribe = this.store.subscribe(handleChange.bind(this, options));
        handleChange.call(this, options)
      }
      if (typeof _onLoad === 'function') {
        _onLoad.call(this, options)
      }
      if (typeof _ready === 'function') {
        _ready.call(this, options)
      }
    }

    function onUnload() {
      if (typeof _onUnload === 'function') {
        _onUnload.call(this)
      }
      if (typeof _detached === 'function') {
        _detached.call(this)
      }
      typeof this.unsubscribe === 'function' && this.unsubscribe()
    }

    /**
     * 兼容Component情况
     */
    const ready = onLoad
    const detached = onUnload

    return assign({}, pageConfig, mapDispatch(app.store.dispatch), {onLoad, onUnload, ready, detached})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants