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

Regular中如何实现高阶组件 #224

Open
Qquanwei opened this issue Sep 25, 2018 · 1 comment
Open

Regular中如何实现高阶组件 #224

Qquanwei opened this issue Sep 25, 2018 · 1 comment

Comments

@Qquanwei
Copy link

例如我需要实现一个组件挂载时给body加上一个类名的高阶组件。

const withBodyClass = Component => 
Component.extend({
  init() {
     document.body.class = 'classname';
  }
  destory() {
    document.body.class = '';
  }
})

但是,貌似Regular的组件并不支持这样。如果我传入一个

const MyComponent = Regular.extend({
    name: 'MyComponent'
    ...
})

const HOBodyClass = withBodyClass(MyComponent);

全局的MyComponent还是原始的定义。

请问Regular中是如何实现这类组件的?

@Qquanwei
Copy link
Author

Qquanwei commented Sep 25, 2018

支持这种写法,应该仅仅需要查找name或其他实例属性的时候增加一步向上ProtoType的查找。这样高阶组件查找到name后就可以覆盖原始的定义。

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

No branches or pull requests

2 participants