opentiny / tiny-vue

TinyVue is an enterprise-class UI component library of OpenTiny community, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.
https://opentiny.design/tiny-vue
MIT License
1.54k stars 253 forks source link

$parent 以及 $children 相关逻辑重构以实现 React、Inula 适配 #1361

Open xiejay97 opened 7 months ago

xiejay97 commented 7 months ago

What problem does this feature solve

以carousel组件为例,在 renderless 中,获取父、子实例是依据 Vue 组件结构实现,如 carousel-item 获取到 carousel 是通过 parent.$parent,这是由于 carousel-item 组件外层有一层适配层组件。这是无法迁移的React中的特性,我们应当通过条件获取准确的父、子实例

What does the proposed API look like

父实例

  function getParent(instance, fn) {
    let parent = instance
    while (parent && !fn(parent)) {
      parent = parent.$parent
    }
    return parent
  }

子实例

  function getChildren(instance, fn) {
    let children = instance
    while (children && children[0] && !fn(children[0])) {
      children = children.$children
    }
    return children
  }
Issues-translate-bot commented 7 months ago

Bot detected the issue body's language is not English, translate it automatically.


Title: $parent and $children related logic refactoring to achieve React and Inula adaptation

zzcr commented 1 month ago

你好,我们正在规划消除$parent和$chilren

Issues-translate-bot commented 1 month ago

Bot detected the issue body's language is not English, translate it automatically.


Hello, we are planning to eliminate $parent and $children