{"action":"closed","issue":{"url":"https://api.github.com/repos/RubyLouvre/avalon/issues/1609","repository_url":"https://api.github.com/repos/RubyLouvre/avalon","labels_url":"https://api.github.com/repos/RubyLouvre/avalon/issues/1609/labels{/name}","comments_url":"https://api.github.com/repos/RubyLouvre/avalon/issues/1609/comments","events_url":"https://api.github.com/repos/RubyLouvre/avalon/issues/1609/events","html_url":"https://github.com/RubyLouvre/avalon/issues/1609","id":166012729,"number":1609,"title":"复制虚拟DOM树","user":{"login":"RubyLouvre","id":190846,"avatar_url":"https://avatars.githubusercontent.com/u/190846?v=3","gravatar_id":"","url":"https://api.github.com/users/RubyLouvre","html_url":"https://github.com/RubyLouvre","followers_url":"https://api.github.com/users/RubyLouvre/followers","following_url":"https://api.github.com/users/RubyLouvre/following{/other_user}","gists_url":"https://api.github.com/users/RubyLouvre/gists{/gist_id}","starred_url":"https://api.github.com/users/RubyLouvre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RubyLouvre/subscriptions","organizations_url":"https://api.github.com/users/RubyLouvre/orgs","repos_url":"https://api.github.com/users/RubyLouvre/repos","events_url":"https://api.github.com/users/RubyLouvre/events{/privacy}","received_events_url":"https://api.github.com/users/RubyLouvre/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/RubyLouvre/avalon/labels/%E5%8A%9F%E8%83%BD%E5%A2%9E%E5%BC%BA","name":"功能增强","color":"a9ea00"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-18T03:15:37Z","updated_at":"2016-07-18T06:33:16Z","closed_at":"2016-07-18T06:33:16Z","body":"```javascript\r\nvar stringify = require('../strategy/parser/stringify')\r\n\r\nfunction enterAction(src, key) {\r\n    var tmpl = src.template + '<!--' + src.signature + '-->'\r\n    var t = cache.get(tmpl)\r\n    if (!t) {\r\n        var vdomTemplate = avalon.lexer(tmpl)\r\n        avalon.speedUp(vdomTemplate)\r\n        t = cache.put(tmpl,  copyVTree(vdomTemplate))\r\n    }\r\n    var c = t()\r\n    c.push({\r\n        nodeType: 8,\r\n        type: '#comment',\r\n        nodeValue: src.signature\r\n    })\r\n    return {\r\n        action: 'enter',\r\n        children: c,\r\n        key: key\r\n    }\r\n}\r\n\r\nfunction copyNode(vdom) {\r\n    switch (vdom.nodeType) {\r\n        case 3:\r\n            if (avalon.config.rexpr.test(vdom.nodeValue)) {\r\n                return stringify(avalon.mix({dynamic: true}, vdom))\r\n            }\r\n            return stringify(vdom)\r\n        case 8:\r\n            if (vdom.dynamic === 'for')\r\n                return stringify(vdom) + ',[]'\r\n            return stringify(vdom)\r\n        case 1:\r\n            var copy = {\r\n                props: {},\r\n                type: vdom.type,\r\n                nodeType: 1\r\n            }\r\n            var copy = avalon.mix({}, vdom)\r\n            delete copy.dom\r\n            delete copy.local\r\n            delete copy.vmodel\r\n            if (!vdom.isVoidTag) {\r\n                copy.children = '[' + vdom.children.map(function (e) {\r\n                    return copyNode(e)\r\n                }).join(', ') + ']'\r\n            } else {\r\n                delete copy.children\r\n            }\r\n            return stringify(copy)\r\n    }\r\n}\r\n\r\n\r\nfunction copyList(vtree) {\r\n    var arr = []\r\n    for (var i = 0, el; el = vtree[i++]; ) {\r\n        if (el.nodeType) {\r\n            arr.push(copyNode(el))\r\n        } else {\r\n            //console.log(el,'xxxx')\r\n            arr.push(copyList(el))\r\n        }\r\n    }\r\n    return '[' + arr.join(', ') + ']'\r\n}\r\nfunction copyVTree(vtree) {\r\n    return new Function('return ' + copyList(vtree))\r\n}\r\n\r\n```"}}
{"actor":{"display_login":"RubyLouvre"}}