Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
perf: 精简头条的 template
Browse files Browse the repository at this point in the history
  • Loading branch information
Pochodaydayup committed Sep 3, 2019
1 parent 1a2502f commit 25872a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
22 changes: 7 additions & 15 deletions packages/remax-cli/templates/toutiao/base.ejs
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
<template name="REMAX_TPL">
<block tt:for="{{tree.root.children}}" tt:key="{{id}}">
<template is="REMAX_TPL_1_CONTAINER" data="{{i: item}}" />
<template is="{{'REMAX_TPL_' + item.type}}" data="{{i: item}}" />
</block>
</template>

<% for (var i = 1; i <= depth; i++) { %>
<%var id = i; %>
<% for (let component of components) { %>
<%- include('./component.ejs', {
type: component.type,
props: component.props,
id: component.id,
templateId: id,
}) %>
<%- include('./component.ejs', {
type: component.type,
props: component.props,
id: component.id,
}) %>
<% } %>
<template name="REMAX_TPL_<%=id%>_plain-text" data="{{i: i}}">
<template name="REMAX_TPL_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>
<% } %>
30 changes: 19 additions & 11 deletions packages/remax-cli/templates/toutiao/component.ejs
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
<% camelCased = function(str) { return str.replace(/-([a-z0-9])/g, function (g) { return g[1].toUpperCase(); })}%>

<template name="REMAX_TPL_<%=templateId%>_<%=id%>">
<template name="REMAX_TPL_<%=id%>">
<<%=id%> <% for(let key of props) { %> <%=key%>="{{i.props.<%=camelCased(key)%>}}" <% } %>>
<% if (id === 'swiper') { %>
<block tt:for="{{i.children}}" tt:key="{{id}}">
<swiper-item key="{{item.props.key}}">
<block tt:for="{{item.children}}" tt:key="{{id}}">
<template is="REMAX_TPL_<%= templateId + 1%>_CONTAINER" data="{{i: item}}" />
</block>
</swiper-item>
</block>
<block tt:for="{{i.children}}" tt:key="{{id}}">
<swiper-item key="{{item.props.key}}">
<block tt:for="{{item.children}}" tt:key="{{id}}">
<template is="{{'REMAX_TPL_' + item.type}}" data="{{i: item}}" />
</block>
</swiper-item>
</block>
<% } else if (id === 'picker-view') { %>
<block tt:for="{{i.children}}" tt:key="{{item.id}}">
<picker-view-column>
<view tt:for="{{item.children}}">
<template is="{{'REMAX_TPL_' + item.type}}" data="{{i: item}}" />
</view>
</picker-view-column>
</block>
<% } else { %>
<block tt:for="{{i.children}}" tt:key="{{id}}">
<template is="REMAX_TPL_<%= templateId + 1%>_CONTAINER" data="{{i: item}}" />
</block>
<block tt:for="{{i.children}}" tt:key="{{id}}">
<template is="{{'REMAX_TPL_' + item.type}}" data="{{i: item}}" />
</block>
<% } %>
</<%=id%>>
</template>

0 comments on commit 25872a1

Please sign in to comment.