- 有了接口就可以请求接口,然后履行返回函数进行 diff apply:
- // curr 为当前的 VirtualDom 树
- if (!curr) return
- var xhr = new XMLHttpRequest()
- xhr.onreadystatechange = function() {
- if (xhr.readyState === 4) {
- if (xhr.status === 200) {
- var text = xhr.responseText
- var func = new Function(text + '\n return $gwx("./' +__path__+ '.wxml")')
- window.__generateFunc__ = func()
- var oldTree = curr
- // 获取当前 data 生成新的树
- var o = m(p.default.getData(), false),
- // 进行 diff apply
- a = oldTree.diff(o);
- a.apply(x);
- document.dispatchEvent(new CustomEvent("pageReRender", {}));
- console.info('Hot apply: ' + __path__ + '.wxml')
- }
推荐阅读
CIO半月刊第十二期|打造“智慧交通”,保障城市高效、安全、智能化运行
【义务编辑:谢海平 TEL:(010)68476606】 >>>详细阅读
本文标题:微信小程序架构分析 (下)
地址:http://www.17bianji.com/lsqh/35676.html
1/2 1