Giter Club home page Giter Club logo

Comments (1)

errorrik avatar errorrik commented on September 27, 2024

这是老ER的问题。新ER里其实也有相应的机制,只不过不在ER这个repo下了。

首先,这基于一种假设:我们认为页面不一定是需要全部变化的。比如我们进入一个列表页面,然后点击了第二页,这时列表的表头可以不用变化,只局部刷新表格的内容区域。要实现这样的场景,我们需要知道什么东西是可变化的。通常情况下,有两种做法:

  1. 自动法:当render时,抽析出模板中变量的部分。这种做法用起来比较方便,但实际上比较麻烦。首先变化的一定是页面中的DOM,但你render的时候面对的是字符串,你需要按相应的规则parse出变化的部分(对应的是什么变量,属于DOM中的什么部分,text还是attr等),才能方便的构建映射。后续更新时,对于复杂的数据结构,你可能需要做diff,这个开销是很大的。
  2. 手动法:手工标识哪些东西是可变的。这个听起来不太现实,使用太麻烦了。但老ER正是这么做的,不是全手工,但是基于了一些规则。

老ER的做法是:

  1. 视图渲染的步骤,在框架层面做了一层抽象,分成render和repaint。当页面首次进入时,进入render过程;当二次进入(hash的path部分不变,参数变化时),进入repaint过程。这个抽象便于在视图渲染中实现局部刷新。但是ER并没规定一定要做这事。
  2. 视图render的步骤是:通过模板引擎填充HTML -> 渲染UI组件(初始化组件 -> 在当前环境下保存组件的引用 -> 为组件填充数据 -> 调用组件的render方法)
  3. 在上面的步骤中,视图能够知道当前有哪些组件,每个组件使用哪些数据了。这时候后面的局部刷新就好做了。在视图repaint中,我们只对组件进行刷新,步骤如下:遍历所有组件 -> 填充数据 -> 调用组件的render方法。

从上面的几点可以看出来:

  1. 局部刷新是由UI组件完成的(一个Table组件,第二次render的时候,只刷数据区域还是刷新全部,这件事情交给Table组件来决定。一个Select,value变化时只刷新显示区域这种事情也是Select自己完成)
  2. 视图缓存也是UI组件完成的(数据不变的时候,视图是否重新刷新,这个逻辑也交给UI组件)

综上,对老ER和ESUI集成的默认方案来说,我们认为UI组件是数据显示与变化的载体。对于你上面的case,建议使用Label组件来承载需要变化的红框文字内容。

from er.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.