MCPcopy Index your code
hub / github.com/Tencent/kbone / constructor

Method constructor

packages/miniprogram-render/src/document.js:92–153  ·  view source on GitHub ↗
(pageId, nodeIdMap)

Source from the content-addressed store, hash-verified

90
91class Document extends EventTarget {
92 constructor(pageId, nodeIdMap) {
93 super()
94
95 const config = cache.getConfig()
96 const runtime = config.runtime || {}
97 const cookieStore = runtime.cookieStore
98 WX_CUSTOM_COMPONENT_MAP = runtime.usingComponents || {}
99
100 this.$_pageId = pageId
101 const pageRoute = tool.getPageRoute(pageId)
102 const pageName = tool.getPageName(pageRoute)
103
104 // 用于封装特殊标签和对应构造器
105 const that = this
106 this.$_imageConstructor = function HTMLImageElement(width, height) {
107 return Image.$$create({
108 tagName: 'img',
109 nodeId: `b-${tool.getId()}`, // 运行时生成,使用 b- 前缀
110 attrs: {},
111 width,
112 height,
113 }, that.$_tree)
114 }
115
116 this.$_pageId = pageId
117 this.$_tree = new Tree(pageId, {
118 type: 'element',
119 tagName: 'body',
120 attrs: {},
121 unary: false,
122 nodeId: 'e-body',
123 children: [],
124 }, nodeIdMap, this)
125 this.$_cookie = new Cookie(pageName)
126 this.$_config = null
127
128 // documentElement
129 this.$_node = this.$$createElement({
130 tagName: 'html',
131 attrs: {},
132 nodeId: `a-${tool.getId()}`, // 运行前生成,使用 a- 前缀
133 })
134 this.$_node.$$updateParent(this) // documentElement 的 parentNode 是 document
135
136 // head 元素
137 this.$_head = this.createElement('head')
138
139 // 更新 body 的 parentNode
140 this.$_tree.root.$$updateParent(this.$_node)
141 this.$_node.$$children.push(this.$_tree.root)
142
143 // 持久化 cookie
144 if (cookieStore !== 'memory' && cookieStore !== 'globalmemory') {
145 try {
146 const key = cookieStore === 'storage' ? `PAGE_COOKIE_${pageName}` : 'PAGE_COOKIE'
147 const cookie = wx.getStorageSync(key)
148 if (cookie) this.$$cookieInstance.deserialize(cookie)
149 } catch (err) {

Callers

nothing calls this directly

Calls 5

$$createElementMethod · 0.95
createElementMethod · 0.95
$$updateParentMethod · 0.80
deserializeMethod · 0.80
$$createMethod · 0.45

Tested by

no test coverage detected