This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 用调用模板的方式替代条件判断 2. 收集使用到的 props ,而不是声明所有 props
- Loading branch information
Showing
12 changed files
with
153 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
<template name="REMAX_TPL"> | ||
<block a:for="{{tree.root.children}}" a:key="{{item.id}}"> | ||
<template is="REMAX_TPL_1" data="{{item}}"/> | ||
<template is="REMAX_TPL_1_CONTAINER" data="{{item: item}}" /> | ||
</block> | ||
</template> | ||
|
||
<template name="REMAX_TPL_1"> | ||
<block> | ||
<block a:if="{{item && item.text}}"> | ||
<!-- string --> | ||
{{item.text}} | ||
</block> | ||
|
||
<% for (let component of components) { %> | ||
<%- include('./component.ejs', { | ||
<% for (let component of components) { %> | ||
<%- include('./component.ejs', { | ||
type: component.type, | ||
props: component.props, | ||
id: component.id, | ||
}) %> | ||
<% } %> | ||
</block> | ||
<% } %> | ||
<template name="REMAX_TPL_1_plain-text"> | ||
<block>{{item.text}}</block> | ||
</template> | ||
<!-- 把动态选择模板的逻辑放入一个模板内,可以提升性能问题 --> | ||
<template name="REMAX_TPL_1_CONTAINER"> | ||
<template is="{{'REMAX_TPL_1_' + item.type}}" data="{{item: item}}" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,31 @@ | ||
<% camelCased = function(str) { return str.replace(/-([a-z0-9])/g, function (g) { return g[1].toUpperCase(); })}%> | ||
|
||
<% | ||
const events = [ | ||
'tap' | ||
]; | ||
props = props.concat(events.map(item => `bind${item}`)); | ||
%> | ||
<block a:if="{{item.type === '<%= type %>'}}"> | ||
<<%=id%> | ||
<% for(let key of props) { %> | ||
<%=key%>="{{item.props.<%=camelCased(key)%>}}" | ||
<% } %> | ||
> | ||
<template name="REMAX_TPL_1_<%=id%>"> | ||
<<%=id%> <% for(let key of props) { %> <%=key%>="{{item.props.<%=camelCased(key)%>}}" <% } %>> | ||
<% if (id === 'swiper') { %> | ||
<block a:for="{{item.children}}" a:key="{{item.id}}"> | ||
<swiper-item key="{{item.props.key}}" > | ||
<block a:for="{{item.children}}"> | ||
<template is="REMAX_TPL_1" data="{{item}}"/> | ||
</block> | ||
</swiper-item> | ||
</block> | ||
<block a:for="{{item.children}}" a:key="{{item.id}}"> | ||
<swiper-item key="{{item.props.key}}"> | ||
<block a:for="{{item.children}}" a:key="{{item.id}}"> | ||
<template is="REMAX_TPL_1_CONTAINER" data="{{item: item}}" /> | ||
</block> | ||
</swiper-item> | ||
</block> | ||
<% } else if (id === 'picker') { %> | ||
<view> | ||
<template is="REMAX_TPL_1" data="{{item: item.children[0]}}"/> | ||
</view> | ||
<view> | ||
<template is="REMAX_TPL_1_CONTAINER" data="{{item: item.children[0]}}" /> | ||
</view> | ||
<% } else if (id === 'picker-view') { %> | ||
<block a:for="{{item.children}}" a:key="{{item.id}}"> | ||
<picker-view-column> | ||
<view a:for="{{item.children}}"> | ||
<template is="REMAX_TPL_1" data="{{item}}"/> | ||
</view> | ||
</picker-view-column> | ||
</block> | ||
<block a:for="{{item.children}}" a:key="{{item.id}}"> | ||
<picker-view-column> | ||
<view a:for="{{item.children}}"> | ||
<template is="REMAX_TPL_1_CONTAINER" data="{{item}}" /> | ||
</view> | ||
</picker-view-column> | ||
</block> | ||
<% } else { %> | ||
<block a:for="{{item.children}}" a:key="{{item.id}}"> | ||
<template is="REMAX_TPL_1" data="{{item}}"/> | ||
</block> | ||
<block a:for="{{item.children}}" a:key="{{item.id}}"> | ||
<template is="REMAX_TPL_1_CONTAINER" data="{{item: item}}" /> | ||
</block> | ||
<% } %> | ||
</<%=id%>> | ||
</block> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<import-sjs name="helper" from="<%= jsHelper %>"/> | ||
<import src="<%= baseTemplate %>"/> | ||
<template is="REMAX_TPL" data="{{tree: helper.reduce(action)}}"/> | ||
<import-sjs name="helper" from="<%= jsHelper %>" /> | ||
<import src="<%= baseTemplate %>" /> | ||
<template is="REMAX_TPL" data="{{tree: helper.reduce(action)}}" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
<template name="REMAX_TPL"> | ||
<block wx:for="{{tree.root.children}}" wx:key="{{item.id}}"> | ||
<template is="REMAX_TPL_1" data="{{i: item}}"/> | ||
<block wx:for="{{tree.root.children}}" wx:key="{{id}}"> | ||
<template is="REMAX_TPL_1_CONTAINER" data="{{i: item}}" /> | ||
</block> | ||
</template> | ||
|
||
<wxs module="_h"> | ||
module.exports = { | ||
v: function(value) { | ||
return value !== undefined ? value : ''; | ||
} | ||
v: function(value) { | ||
return value !== undefined ? value : ''; | ||
} | ||
}; | ||
</wxs> | ||
|
||
<% for (var i = 1; i <= depth; i++) { %> | ||
<%var id = i; %> | ||
<template name="REMAX_TPL_<%= id%>"> | ||
<block> | ||
<block wx:if="{{i && i.text}}">{{i.text}}</block> | ||
<% for (let component of components) { %> | ||
<%- include('./component.ejs', { | ||
<%var id = i; %> | ||
<% for (let component of components) { %> | ||
<%- include('./component.ejs', { | ||
type: component.type, | ||
props: component.props, | ||
id: component.id, | ||
templateId: id + 1 | ||
templateId: id, | ||
}) %> | ||
<% } %> | ||
</block> | ||
</template> | ||
<% } %> | ||
<template name="REMAX_TPL_<%=id%>_plain-text" data="{{i: i}}"> | ||
<block>{{i.text}}</block> | ||
</template> | ||
<!-- 把动态选择模板的逻辑放入一个模板内,可以提升性能问题 --> | ||
<template name="REMAX_TPL_<%=id%>_CONTAINER" data="{{i: i}}"> | ||
<template is="{{'REMAX_TPL_<%=id%>_' + i.type}}" data="{{i: i}}" /> | ||
</template> | ||
<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
<% camelCased = function(str) { return str.replace(/-([a-z0-9])/g, function (g) { return g[1].toUpperCase(); })}%> | ||
|
||
<block wx:if="{{i.type === '<%= type %>'}}"> | ||
<<%=id%> | ||
<% for(let key of props) { %> | ||
<%=key%>="{{_h.v(i.props.<%=camelCased(key)%>)}}" | ||
<% } %> | ||
><% if (id === 'swiper') { %> | ||
<block wx:for="{{i.children}}" wx:key="{{item.id}}"> | ||
<swiper-item key="{{item.props.key}}" > | ||
<block wx:for="{{item.children}}" wx:key="{{item.id}}"> | ||
<template is="REMAX_TPL_<%= templateId%>" data="{{ i: item}}"/> | ||
</block> | ||
</swiper-item> | ||
</block> | ||
<template name="REMAX_TPL_<%=templateId%>_<%=id%>"> | ||
<<%=id%> <% for(let key of props) { %> <%=key%>="{{_h.v(i.props.<%=camelCased(key)%>)}}" <% } %>> | ||
<% if (id === 'swiper') { %> | ||
<block wx:for="{{i.children}}" wx:key="{{id}}"> | ||
<swiper-item key="{{item.props.key}}"> | ||
<block wx:for="{{item.children}}" wx:key="{{id}}"> | ||
<template is="REMAX_TPL_<%= templateId + 1%>_CONTAINER" data="{{i: item}}" /> | ||
</block> | ||
</swiper-item> | ||
</block> | ||
<% } else { %> | ||
<block wx:for="{{i.children}}" wx:key="{{item.id}}"> | ||
<template is="REMAX_TPL_<%= templateId%>" data="{{i: item}}"/></block> | ||
<block wx:for="{{i.children}}" wx:key="{{id}}"> | ||
<template is="REMAX_TPL_<%= templateId + 1%>_CONTAINER" data="{{i: item}}" /> | ||
</block> | ||
<% } %> | ||
</<%=id%>> | ||
</block> | ||
</template> |
Oops, something went wrong.