Hanks10100 / weex-native-directive

Weex native directive design
67 stars 14 forks source link

Simplified syntax? #15

Open yyx990803 opened 6 years ago

yyx990803 commented 6 years ago

Currently it seems switch and case attributes (previously template-key and template-type) are always required, even when there is only one <cell-slot>.

I think when there is only one <cell-slot>, it should be used by default, so switch and case can be omitted:

<recycle-list for="item in longList">
  <cell-slot>
    <text>{{ item.foo }}</text>
  </cell-slot>
</recycle-list>
Hanks10100 commented 6 years ago

That's great. The switch and case should be optional.

Furthermore, we should clarify some edge cases.

1. If there is no switch

Only use the first <cell-slot> to render all data in longList. The case property is no longer useful. Even if there are more than one <cell-slot>, the rest will be ignored.

2. Support the default attribute

If switch exists and some <cell-slot> contains the default attribute, it should be rendered only if the type of item data doesn't match any case.

<recycle-list for="item in longList" switch="type">
  <cell-slot case="label">
    <text>{{ item.foo }}</text>
  </cell-slot>
  <cell-slot default>
    <text>{{ item.bar }}</text>
  </cell-slot>
</recycle-list>

Only the first default is valid, the rest will be ignored.

3. If switch exists, but some <cell-slot> has no case or default

Those <cell-slot>s should be ignored.

yyx990803 commented 6 years ago

I think we should also throw warnings for case 1 and 3.