未加星标

Virtual DOM and me - it's complicated

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二03 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

I have mixed feelings about virtual DOM. I get it: it’s cool, it’s different, it’s everywhere, it’s pure, it’s hipster. Thing is it’s not how the DOM works and that’s the issue for me.

You see, DOM is mutable. If you want to have static layouts and switch between them virtual DOM is ok. That’s just not enough for me. I started with Flash in 1999 and I like interactions, animations, tailor-made components and nice little details. I also want to control what’s happening, when and how. Virtual DOM doesn’t let me do all that the way I want. It gets in the way.

When you want to have some 3rd party component like Google Maps, things get even more complicated. You need some 4th party dependency to handle virtual DOM mutable DOM conversion. Or be mutable and save the reference to the component, cross fingers and hope virtual DOM doesn’t mess things up.

Also to prevent virtual DOM doing extra work, you need keys everywhere. In the mutable world you don’t need them, because things stay where you put them. And for example by saving references to a lookup table you can reorder really easily. You can even control which parts of the component are static and which not. With virtual DOM you need to do it with a hack (shouldComponentUpdate or whatever).

What if you want to have a fadeout animation? What if another update comes before the transition ends? How would virtual DOM know where to put that element between the states? Yes, again there’s 3rd party dependencies, but you’ll end up with fatigue after some dozen of them. And if you want to have something more customized, you’re screwed. You don’t need to think those kind of things with the mutable DOM.

You can even make pure updates with the mutable DOM if you want. Check out my tiny UI library RE:DOM for example. It doesn’t use virtual DOM. Still it’s super fast, easy to use and you can always rerender components if you want, but separate which parts are static and which dynamic. You can even use RE:DOM in the server, with NO:DOM .

Virtual DOM might work for some, but it’s not for me. There, I’ve said it.

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

分页:12
转载请注明
本文标题:Virtual DOM and me - it's complicated
本站链接:http://www.codesec.net/view/483368.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(47)