Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat dynamic v2 #1486

Merged
merged 207 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 190 commits
Commits
Show all changes
207 commits
Select commit Hold shift + click to select a range
0bf2108
[feat]feat-dynamic
CommanderXL Aug 22, 2023
0e2203f
[refactor]优化构建流程&解释器
CommanderXL Sep 6, 2023
d41a5a6
[merge]merge from master
CommanderXL Sep 6, 2023
ec2734b
[chore]add some comments
CommanderXL Sep 6, 2023
41bd2e8
[merge]merge from master
CommanderXL Sep 8, 2023
f08fe50
[merge]merge 2.9
CommanderXL Jan 24, 2024
d706487
Merge branch 'master' into feat-dynamic
CommanderXL Jan 29, 2024
b4091f9
[update]支持自定义组件
CommanderXL Feb 5, 2024
597967b
[merge]merge from remote
CommanderXL Feb 5, 2024
f33bce4
[update]add style scope feature
CommanderXL Feb 5, 2024
f7a81eb
fix: ali support
mater1996 Feb 20, 2024
f948d70
[update]样式隔离优化
CommanderXL Feb 27, 2024
67f9e6f
Merge branch 'master' into feat-dynamic
CommanderXL Feb 27, 2024
2f34dc7
[update]处理mpx-custom-element动态注入组件逻辑
CommanderXL Feb 27, 2024
7367296
fix: ali support
mater1996 Feb 27, 2024
c64d241
[fix]列表循环数据污染问题
CommanderXL Feb 27, 2024
d149544
[update]自定义组件渲染优化
CommanderXL Mar 6, 2024
ef5556e
[update]clear code
CommanderXL Mar 12, 2024
2f5a80b
Merge branch 'master' into feat-dynamic
CommanderXL Mar 12, 2024
45c6da5
[fix]fix reactive data diff
CommanderXL Mar 12, 2024
52e7ffc
fix: 收集compoent优化
mater1996 Mar 14, 2024
4b097a8
fix: postProcessRuntime top
mater1996 Mar 14, 2024
880323a
fix: 优化buildTemplate
mater1996 Mar 14, 2024
9bcf15c
refactor: 优化查找runtimeComponent tag逻辑
mater1996 Mar 15, 2024
8289f92
fix: conflict
mater1996 Mar 15, 2024
1165e4f
Merge pull request #2 from CommanderXL/feature/ali-support
CommanderXL Mar 15, 2024
ec830dd
[optimize]优化编译产出ast node体积
CommanderXL Mar 18, 2024
33661a6
Merge branch 'feat-dynamic' of github.com:CommanderXL/mpx into feat-d…
CommanderXL Mar 18, 2024
b2fd0c3
[chore]fix lint
CommanderXL Mar 19, 2024
1e8d328
[optimize]parse exps types
CommanderXL Mar 21, 2024
8579f1b
feat: static view + default block node
mater1996 Mar 21, 2024
d87faa5
fix: comment
mater1996 Mar 21, 2024
865836b
feat: 只支持类选择器
mater1996 Mar 22, 2024
7fe2ca8
Merge branch 'feat-dynamic' into feat-class-selector
mater1996 Mar 22, 2024
f9e9117
feat: minisize
mater1996 Apr 1, 2024
f299b5c
[optimize]some code
CommanderXL Apr 1, 2024
19d9324
feat: minisize
mater1996 Apr 2, 2024
f8630df
fix: remove console
mater1996 Apr 2, 2024
18e9455
fix: revert
mater1996 Apr 2, 2024
c4f50fe
fix: revert
mater1996 Apr 2, 2024
4541171
fix: remove node minisize
mater1996 Apr 7, 2024
bad7e91
fix: foamt
mater1996 Apr 7, 2024
815dcff
fix: remove render.old
mater1996 Apr 7, 2024
27d3da1
[optimize]优化体积&支持属性单值写法
CommanderXL Apr 9, 2024
f50d626
[fix]lint
CommanderXL Apr 9, 2024
468ddbe
[optimize]暂时去掉 mpxAttrs 大对象属性,目前使用不到
CommanderXL Apr 9, 2024
611ff78
[update]optimize some code
CommanderXL Apr 17, 2024
f7d5b88
Merge pull request #3 from CommanderXL/feature/ali-support
CommanderXL Apr 17, 2024
f9a1fe7
fix: conflict
mater1996 Apr 17, 2024
3ca7b38
Merge pull request #5 from CommanderXL/feat-minisize
CommanderXL Apr 17, 2024
916e313
fix: rename internalComponents => baseComponents
mater1996 Apr 18, 2024
e6faa81
feat: init
mater1996 Apr 19, 2024
9b5433c
[optimize]依赖关系后置
CommanderXL Apr 19, 2024
be25abb
merge
CommanderXL Apr 19, 2024
6a697d9
[chore]clear cide
CommanderXL Apr 19, 2024
3743725
[optimize]optimize code
CommanderXL Apr 22, 2024
47b9226
feat: dynamic render
mater1996 Apr 22, 2024
fce419a
fix: conflict
mater1996 Apr 22, 2024
50ab16a
fix: resultSource error
mater1996 Apr 22, 2024
e468fb5
fix: rename dynamicRender to _getAst and lint
mater1996 Apr 22, 2024
7e9095a
fix: _getAst
mater1996 Apr 22, 2024
d700963
Merge pull request #8 from CommanderXL/feature/dynamic-query-and-dyna…
CommanderXL Apr 22, 2024
9db2551
feat: base node optimize
mater1996 Apr 24, 2024
9e6fdda
Merge pull request #9 from CommanderXL/feature/node-optimize
CommanderXL Apr 25, 2024
adf1ec0
[optimize]event propagation
CommanderXL Apr 25, 2024
e65b1d2
[merge]
CommanderXL Apr 25, 2024
1f654c3
feat: 优化组件节点属性
mater1996 Apr 25, 2024
6c3718d
Merge pull request #11 from CommanderXL/feature/optimize-component
CommanderXL Apr 25, 2024
3aa6a27
fix: ali event 没生效
mater1996 Apr 25, 2024
dc0f153
[fix]arr render err
CommanderXL Apr 26, 2024
1745d00
[fix]cache name
CommanderXL Apr 26, 2024
3717799
[chore]clear code
CommanderXL Apr 26, 2024
3ecb51a
Update render.js
mater1996 Apr 28, 2024
7b12487
[optimize]generate of mpx-custom-element
CommanderXL May 8, 2024
e87de56
[chore]clear code
CommanderXL May 9, 2024
33a9574
fix: 修复多个style动态化收集信息时,style覆盖内容的问题
mater1996 May 9, 2024
a162068
[optimize]优化事件处理
CommanderXL May 10, 2024
8485065
fix: refactor code
mater1996 May 11, 2024
c065bc1
Merge pull request #12 from CommanderXL/bugfix/multiple-style-tag
CommanderXL May 11, 2024
a6aedfa
feat: wxs utils
mater1996 May 11, 2024
bb792ff
fix: element
mater1996 May 11, 2024
e845caf
fix: eslint wxs
mater1996 May 11, 2024
50cacfd
Merge pull request #14 from CommanderXL/feat-wxs-utils
CommanderXL May 11, 2024
7fa6d8c
fix: remove alias tag
mater1996 May 15, 2024
f05dd69
[fix]调整acorn编译模式,支持在严格模式下保留关键字的编译
CommanderXL May 17, 2024
3124386
[optimize]优化渲染过程的报错信息
CommanderXL May 20, 2024
61ec299
[merge]merge from remote master
CommanderXL May 20, 2024
19b7da0
refactor: base-wxml
mater1996 May 22, 2024
07ce903
Merge branch 'feat-dynamic-v2' of github.com:CommanderXL/mpx into fea…
mater1996 May 22, 2024
1533089
fix: base-wxml收集错误
mater1996 May 22, 2024
dabdf9f
fix: revert base-wxml
mater1996 May 22, 2024
9e41c8f
fix: rever
mater1996 May 22, 2024
ffa4cb0
fix: base-wxml
mater1996 May 22, 2024
31939bf
[fix]复杂依赖关系下的slot渲染问题
CommanderXL May 22, 2024
67969b7
Merge branch 'feat-dynamic-v2' of github.com:CommanderXL/mpx into fea…
CommanderXL May 22, 2024
76c580d
Merge pull request #15 from CommanderXL/bugfix-base-wxml
CommanderXL May 22, 2024
c24e836
[optimize]clear code&优化运行时组件产出物流程
CommanderXL May 23, 2024
e81160c
[chore]clear code
CommanderXL May 24, 2024
37b9cb1
[optimize]优化代码结构
CommanderXL May 24, 2024
a9ec3d8
[chore]clear code
CommanderXL May 24, 2024
bcf367f
[merge]merge from remote master
CommanderXL May 24, 2024
9240515
[chore]clear code
CommanderXL May 24, 2024
d4d2321
feat: 分离wxs以及custom.mpx到template-engine
mater1996 May 29, 2024
5a89e29
fix: merge conflict
mater1996 May 29, 2024
cdde0e9
feat: add template-engine dep
mater1996 May 29, 2024
d184044
fix: template engine version
mater1996 May 29, 2024
bf66ceb
Merge pull request #16 from CommanderXL/feature/mv-wxs
CommanderXL May 29, 2024
ba22048
[optimize]优化动态组件收集slot依赖的逻辑
CommanderXL May 29, 2024
4d68a6c
Merge branch 'feat-dynamic-v2' of github.com:CommanderXL/mpx into fea…
CommanderXL May 29, 2024
573b44d
[fix]复杂slot依赖场景注入的问题
CommanderXL May 29, 2024
2fdf1ff
[optimize]优化动态容器组件静态内容注入流程
CommanderXL May 30, 2024
56f4c19
feat: dynamic render 动态注入
mater1996 Jun 17, 2024
1459098
fix: change
mater1996 Jun 17, 2024
d65c3ac
fix: remove unused code
mater1996 Jun 17, 2024
74b8f16
[fix]cr
CommanderXL Jun 17, 2024
0f6e58d
[optimize]reset extractor logic
CommanderXL Jun 17, 2024
3456802
fix: conflict
mater1996 Jun 17, 2024
a90b34d
fix: conflict
mater1996 Jun 17, 2024
750da99
feat: dynamicRuntime and normalice getAst function
mater1996 Jun 17, 2024
47b6540
fix: conflict
mater1996 Jun 17, 2024
5e3a324
feat: core dynamic slot mixin
mater1996 Jun 18, 2024
ad8cb61
[chore]add comment
CommanderXL Jun 18, 2024
d870d07
fix: mixin slot
mater1996 Jun 18, 2024
8b7d5d8
fix: remove inline eslint rule
mater1996 Jun 18, 2024
006d01e
fix: queryObj get error
mater1996 Jun 18, 2024
d237137
Merge pull request #17 from CommanderXL/feature/cr-feat
CommanderXL Jun 18, 2024
842266c
[chore]little fix
CommanderXL Jun 18, 2024
97b2cd6
fix: 修复收集替换后元素的属性
mater1996 Jun 18, 2024
733951e
Merge pull request #19 from CommanderXL/bugfix/collect-replace-node
CommanderXL Jun 18, 2024
4ff026c
[chore]clear code
CommanderXL Jun 18, 2024
b4f5a34
Merge branch 'feat-dynamic-v2' of github.com:CommanderXL/mpx into fea…
CommanderXL Jun 18, 2024
a54dc5b
[optimize]优化异步分包处理流程
CommanderXL Jun 19, 2024
4eac950
feat: dynamic process merge to compiler
mater1996 Jun 19, 2024
b74beb3
Merge branch 'feat-dynamic-v2' of github.com:CommanderXL/mpx into fea…
mater1996 Jun 19, 2024
dc3387a
fix: remove try catch
mater1996 Jun 19, 2024
c97e266
fix: add line
mater1996 Jun 19, 2024
2eb1860
fix: uselessAttrs
mater1996 Jun 19, 2024
63391b5
fix: uselessArrAttrs
mater1996 Jun 19, 2024
bc05158
fix: host el
mater1996 Jun 19, 2024
acace70
fix: el
mater1996 Jun 19, 2024
cb06458
fix: optimize code
mater1996 Jun 19, 2024
721828f
fix: optimize code
mater1996 Jun 19, 2024
d18cc93
fix: ali root view process
mater1996 Jun 20, 2024
728db56
fix: 循环引用问题
mater1996 Jun 20, 2024
117b225
fix: dynamic inject dynamic runtime mixin
mater1996 Jun 20, 2024
8c82edc
[optimize]优化RecordRuntimeInfoDependency结构
CommanderXL Jun 20, 2024
6ae7772
fix: post process all
mater1996 Jun 20, 2024
0a6054a
fix: remove cache
mater1996 Jun 20, 2024
7960aa1
fix: remove unuused code
mater1996 Jun 20, 2024
43f80aa
[optimize]抽离dynamicRef动态注入
CommanderXL Jun 20, 2024
b1f72d8
fix: optimize code
mater1996 Jun 21, 2024
4fcbeba
fix: optimize code
mater1996 Jun 21, 2024
ec3dbfa
fix: format change
mater1996 Jun 21, 2024
f5ba2f4
fix: mixin
mater1996 Jun 21, 2024
56d1ec2
fix: optimize code
mater1996 Jun 21, 2024
4f78ebe
Merge pull request #21 from CommanderXL/feature/dynamic-inject-render…
CommanderXL Jun 21, 2024
3764cf7
fix: clone attr
mater1996 Jun 21, 2024
57ced8e
fix: revert code
mater1996 Jun 21, 2024
5d72826
fix: remove dynamic flag
mater1996 Jun 21, 2024
6a4b6c6
fix: add dynamic render options judge
mater1996 Jun 21, 2024
df7544f
fix: options judge
mater1996 Jun 21, 2024
f84b1ee
fix: error tips
mater1996 Jun 21, 2024
99b97cc
fix: remove attr.dynamic
mater1996 Jun 21, 2024
43226de
[merge]merge from master
CommanderXL Jun 21, 2024
a4f2d65
fix: error tips
mater1996 Jun 21, 2024
6ec93e6
Merge pull request #22 from CommanderXL/feature/dynamic-inject-render…
CommanderXL Jun 21, 2024
07d9a1b
Merge pull request #20 from CommanderXL/feature/dynamic-process
CommanderXL Jun 21, 2024
cbdb4a4
fix: remove collectDataset
mater1996 Jun 21, 2024
72ae9ce
[optimize]rename
CommanderXL Jun 21, 2024
d6e0416
fix: 优化dynamic compiler
mater1996 Jun 24, 2024
67af11f
fix: optimize if process
mater1996 Jun 25, 2024
651a23e
fix: remove unused code
mater1996 Jun 25, 2024
36d5356
fix: remove findPrevIfNodeDynamic
mater1996 Jun 25, 2024
43cd1b3
Merge pull request #23 from CommanderXL/feature/optimize-dynamic-comp…
CommanderXL Jun 25, 2024
ab82669
feat: addExps
mater1996 Jun 26, 2024
9d2eda1
fix: ali exps
mater1996 Jun 26, 2024
ed32df1
fix: processClassDynamic
mater1996 Jun 26, 2024
9c07319
fix: code style
mater1996 Jun 26, 2024
b636a0b
fix: ali processAttrs for wrap view
mater1996 Jun 26, 2024
0381dcf
feat: support mpx show
mater1996 Jun 26, 2024
e43a793
fix: dynamicItem
mater1996 Jun 26, 2024
d880801
fix: processStyle
mater1996 Jun 27, 2024
3bcf87b
fix: remove ifProcessed
mater1996 Jun 27, 2024
c268f87
Merge pull request #24 from CommanderXL/feature/exps
CommanderXL Jun 27, 2024
b4f6a34
fix: judge staticStyle
mater1996 Jun 27, 2024
b419f45
fix: add ;
mater1996 Jun 27, 2024
eabae6d
fix: staticStyle
mater1996 Jun 27, 2024
4a77b9f
Merge branch 'feat-dynamic-v2' into feature/exps
mater1996 Jun 27, 2024
b3bd5ce
fix: cr change
mater1996 Jun 27, 2024
ab70f6b
Merge pull request #25 from CommanderXL/feature/exps
CommanderXL Jun 27, 2024
ec3a46e
Merge branch 'master' into feat-dynamic-v2
CommanderXL Jun 27, 2024
842f631
fix: cr change
mater1996 Jun 27, 2024
be30c4e
fix: replace __exps to __exp
mater1996 Jun 27, 2024
4a319e5
fix: merge remove direcive
mater1996 Jun 27, 2024
dda3328
Merge pull request #26 from CommanderXL/feature/exps
CommanderXL Jun 27, 2024
7c9c53f
[update]merge from master
CommanderXL Jun 27, 2024
03800a7
Merge branch 'feat-dynamic-v2' of github.com:CommanderXL/mpx into fea…
CommanderXL Jun 27, 2024
23a486b
[lint]fix lint
CommanderXL Jun 27, 2024
cc0d5f5
Merge branch 'master' into feat-dynamic-v2
CommanderXL Jun 27, 2024
ba119c3
fix: merge master ali process order
mater1996 Jun 27, 2024
b8e36e9
Merge branch 'feat-dynamic-v2' of github.com:CommanderXL/mpx into fea…
mater1996 Jun 27, 2024
d17cf03
Merge pull request #27 from CommanderXL/feature/merge-master-confict
CommanderXL Jun 27, 2024
25dc3e8
fix: postMoveBaseDirective options
mater1996 Jun 27, 2024
8e83610
Merge pull request #28 from CommanderXL/feature/merge-master-confict
mater1996 Jun 27, 2024
1aae96f
fix: webapck plugin dep
mater1996 Jun 27, 2024
e28a4cd
fix: processAttrs for ali wrap view
mater1996 Jun 27, 2024
370890d
fix: add @mpxjs/template-eigine dep
mater1996 Jun 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
App: 'readonly',
__mpx_mode__: 'readonly',
__mpx_env__: 'readonly',
__mpx_dynamic_runtime__: 'readonly',
getRegExp: 'readonly',
getCurrentPages: 'readonly'
},
Expand All @@ -33,6 +34,6 @@ module.exports = {
},
env: {
'jest/globals': true,
'browser': true
browser: true
}
}
4 changes: 2 additions & 2 deletions docs-vuepress/articles/mpx2.md
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ class MPXProxy {
this.miniRenderData = {}
for (let key in renderData) { // 遍历数据访问路径
if (renderData.hasOwnProperty(key)) {
let item = renderData[key]
let item = renderData[key]
let data = item[0]
let firstKey = item[1] // 某个字段 path 的第一个 key 值
if (this.localKeys.indexOf(firstKey) > -1) {
Expand Down Expand Up @@ -817,7 +817,7 @@ class MPXProxy {
* @param {Object} renderData
* @return {Object} processedRenderData
*/
export function preprocessRenderData (renderData) {
export function preprocessRenderData (renderData) {
// method for get key path array
const processKeyPathMap = (keyPathMap) => {
let keyPath = Object.keys(keyPathMap)
Expand Down
50 changes: 48 additions & 2 deletions packages/core/src/core/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import {
ONHIDE,
ONRESIZE
} from './innerLifecycle'
import contextMap from '../dynamic/vnode/context'
import { getAst } from '../dynamic/astCache'

let uid = 0

Expand Down Expand Up @@ -131,6 +133,8 @@ export default class MpxProxy {
}

created () {
// 缓存上下文,在 destoryed 阶段删除
contextMap.set(this.uid, this.target)
if (__mpx_mode__ !== 'web') {
// web中BEFORECREATE钩子通过vue的beforeCreate钩子单独驱动
this.callHook(BEFORECREATE)
Expand Down Expand Up @@ -190,6 +194,8 @@ export default class MpxProxy {
}

unmounted () {
// 页面/组件销毁清除上下文的缓存
contextMap.remove(this.uid)
this.callHook(BEFOREUNMOUNT)
this.scope?.stop()
if (this.update) this.update.active = false
Expand Down Expand Up @@ -379,7 +385,10 @@ export default class MpxProxy {
this.doRender(this.processRenderDataWithStrictDiff(renderData))
}

renderWithData (skipPre) {
renderWithData (skipPre, vnode) {
if (vnode) {
return this.doRenderWithVNode(vnode)
}
const renderData = skipPre ? this.renderData : preProcessRenderData(this.renderData)
this.doRender(this.processRenderDataWithStrictDiff(renderData))
// 重置renderData准备下次收集
Expand Down Expand Up @@ -478,6 +487,25 @@ export default class MpxProxy {
return result
}

doRenderWithVNode (vnode) {
if (!this._vnode) {
this.target.__render({ r: vnode })
} else {
let diffPath = diffAndCloneA(vnode, this._vnode).diffData
if (!isEmptyObject(diffPath)) {
// 构造 diffPath 数据
diffPath = Object.keys(diffPath).reduce((preVal, curVal) => {
const key = 'r' + curVal
preVal[key] = diffPath[curVal]
return preVal
}, {})
this.target.__render(diffPath)
}
}
// 缓存本地的 vnode 用以下一次 diff
this._vnode = diffAndCloneA(vnode).clone
}

doRender (data, cb) {
if (typeof this.target.__render !== 'function') {
error('Please specify a [__render] function to render view.', this.options.mpxFileResource)
Expand Down Expand Up @@ -545,12 +573,30 @@ export default class MpxProxy {
const _c = this.target._c.bind(this.target)
const _r = this.target._r.bind(this.target)
const _sc = this.target._sc.bind(this.target)
const _g = this.target._g?.bind(this.target)
const __getAst = this.target.__getAst?.bind(this.target)
const moduleId = this.target.__moduleId
const dynamicTarget = this.target.__dynamic

const effect = this.effect = new ReactiveEffect(() => {
// pre render for props update
if (this.propsUpdatedFlag) {
this.updatePreRender()
}

if (dynamicTarget || __getAst) {
try {
const ast = getAst(__getAst, moduleId)
return _r(false, _g(ast, moduleId))
} catch (e) {
e.errType = 'mpx-dynamic-render'
e.errmsg = e.message
if (!__mpx_dynamic_runtime__) {
return error('Please make sure you have set dynamicRuntime true in mpx webpack plugin config because you have use the dynamic runtime feature.', this.options.mpxFileResource, e)
} else {
return error('Dynamic rendering error', this.options.mpxFileResource, e)
}
}
}
if (this.target.__injectedRender) {
try {
return this.target.__injectedRender(_i, _c, _r, _sc)
Expand Down
25 changes: 25 additions & 0 deletions packages/core/src/dynamic/astCache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { isFunction, isObject, error } from '@mpxjs/utils'

class DynamicAstCache {
#astCache = {}

getAst (id) {
return this.#astCache[id]
}

setAst (id, ast) {
this.#astCache[id] = ast
}
}

export const dynamic = new DynamicAstCache()

export const getAst = (__getAst, moduleId) => {
if ((__getAst && isFunction(__getAst))) {
const ast = __getAst()
if (!isObject(ast)) return error('__getAst returned data is not of type object')
return Object.values(ast)[0]
} else {
return dynamic.getAst(moduleId)
}
}
77 changes: 77 additions & 0 deletions packages/core/src/dynamic/dynamicRenderMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { hasOwn, isObject, error } from '@mpxjs/utils'
import genVnodeTree from './vnode/render'
import contextMap from './vnode/context'
import { CREATED } from '../core/innerLifecycle'

function dynamicRefsMixin () {
return {
[CREATED] () {
// 处理ref场景,如果是在容器组件的上下文渲染
if (this.mpxCustomElement) {
this._getRuntimeRefs()
}
},
methods: {
_getRuntimeRefs () {
const vnodeContext = contextMap.get(this.uid)
if (vnodeContext) {
const refsArr = vnodeContext.__getRefsData && vnodeContext.__getRefsData()
if (Array.isArray(refsArr)) {
refsArr.forEach((ref) => {
const all = ref.all
if (!vnodeContext.$refs[ref.key] || (all && !vnodeContext.$refs[ref.key].length)) {
const refNode = this.__getRefNode(ref)
if ((all && refNode.length) || refNode) {
Object.defineProperty(vnodeContext.$refs, ref.key, {
enumerable: true,
configurable: true,
get: () => {
return refNode
}
})
}
}
})
}
}
}
}
}
}

function dynamicSlotMixin () {
if (__mpx_mode__ === 'ali') {
return {
props: { slots: {} }
}
} else {
return {
properties: { slots: { type: Object } }
}
}
}

function dynamicRenderHelperMixin () {
return {
methods: {
_g (astData, moduleId) {
const location = this.__mpxProxy && this.__mpxProxy.options.mpxFileResource
if (astData && isObject(astData) && hasOwn(astData, 'template')) {
const vnodeTree = genVnodeTree(astData, [this], { moduleId, location })
return vnodeTree
} else {
error('Dynamic component get the wrong json ast data, please check.', location, {
errType: 'mpx-dynamic-render',
errmsg: 'invalid json ast data'
})
}
}
}
}
}

export {
dynamicRefsMixin,
dynamicSlotMixin,
dynamicRenderHelperMixin
}
17 changes: 17 additions & 0 deletions packages/core/src/dynamic/vnode/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const cache = {}

const contextMap = {
set (id, context) {
cache[id] = context
},
get (id) {
return cache[id]
},
remove (id) {
if (cache[id]) {
delete cache[id]
}
}
}

export default contextMap
Loading
Loading