提交 7c48ee1f 编写于 作者: fxy060608's avatar fxy060608

refactor(v3): renderjs

上级 43d111b9
此差异已折叠。
......@@ -1047,6 +1047,12 @@ function createSelectorQuery () {
return this
};
}
if (!query.in) {
query.in = function () {
return this
};
}
return query
}
......
......@@ -168,12 +168,15 @@ at ${resourcePath}.vue:1`)
}
const filterTemplate = []
options.mp.filterModules.forEach(name => {
filterTemplate.push(
options.mp.platform.createFilterTag(
options.filterTagName,
options.filterModules[name]
const filterModule = options.filterModules[name]
if (filterModule.type !== 'renderjs' && filterModule.attrs.lang !== 'renderjs') {
filterTemplate.push(
options.mp.platform.createFilterTag(
options.filterTagName,
options.filterModules[name]
)
)
)
}
})
if (filterTemplate.length) {
......
......@@ -36,7 +36,8 @@ function getProvides (isAppService) {
'getRegExp': [wxsPath, 'getRegExp']
}
}
return { // app-view
return { // app-view
'__f__': [path.resolve(__dirname, '../format-log.js'), 'default'],
'getDate': [wxsPath, 'getDate'],
'getRegExp': [wxsPath, 'getRegExp']
}
......@@ -89,12 +90,12 @@ const v3 = {
'../../packages/webpack-uni-app-loader/view/script')
})
// view 层 renderjs
rules.push({
resourceQuery: [/lang=renderjs/, /blockType=renderjs/],
use: [{
loader: path.resolve(__dirname, '../../packages/webpack-uni-app-loader/view/renderjs')
}]
})
// rules.push({
// resourceQuery: [/lang=renderjs/, /blockType=renderjs/],
// use: [{
// loader: path.resolve(__dirname, '../../packages/webpack-uni-app-loader/view/renderjs')
// }]
// })
}
scriptLoaders.push({
loader: path.resolve(__dirname,
......
......@@ -27,13 +27,14 @@ module.exports = function parseCustomBlocks(descriptor, options) {
return true
}
if ( // renderjs
options.isAppView &&
block.attrs.module &&
(
block.type === 'renderjs' ||
block.attrs.lang === 'renderjs'
)
) {
return true
descriptor.renderjs = block
modules[block.attrs.module] = block
}
})
......
......@@ -141,6 +141,20 @@ module.exports = function (source) {
)
}
let renderjsImport = `var renderjs`
if(options.isAppView && descriptor.renderjs){
const src = descriptor.renderjs.src || resourcePath
const attrsQuery = attrsToQuery(descriptor.renderjs.attrs, 'js')
const query = `?vue&type=renderjs${attrsQuery}${inheritQuery}`
const request = stringifyRequest(src + query)
renderjsImport = (
`import renderjs from ${request}\n` +
`renderjs.__module = '${descriptor.renderjs.attrs.module}'\n` +
`export * from ${request}` // support named exports
)
}
// styles
let stylesCode = ``
// fixed by xxxxxx 仅限 view 层
......@@ -158,6 +172,7 @@ module.exports = function (source) {
// fixed by xxxxxx (injectStyles,auto components)
let code = `
${templateImport}
${renderjsImport}
${scriptImport}
${stylesCode}
......@@ -172,7 +187,8 @@ var component = normalizer(
${hasScoped ? JSON.stringify(id) : `null`},
${isServer ? JSON.stringify(hash(request)) : `null`},
${isShadow ? `true` : `false`},
components
components,
renderjs
)
`.trim() + `\n`
......
......@@ -13,7 +13,8 @@ export default function normalizeComponent (
scopeId,
moduleIdentifier, /* server only */
shadowMode, /* vue-cli only */
components // fixed by xxxxxx auto components
components, // fixed by xxxxxx auto components
renderjs // fixed by xxxxxx renderjs
) {
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
......@@ -24,6 +25,13 @@ export default function normalizeComponent (
if (components) {
options.components = Object.assign(components, options.components || {})
}
// fixed by xxxxxx renderjs
if (renderjs) {
(renderjs.beforeCreate || (renderjs.beforeCreate = [])).unshift(function() {
this[renderjs.__module] = this
});
(options.mixins || (options.mixins = [])).push(renderjs)
}
// render functions
if (render) {
......
......@@ -30,6 +30,19 @@ module.exports = function selectBlock (
return
}
// renderjs
if (query.type === `renderjs`) {
if (appendExtension) {
loaderContext.resourcePath += '.js'
}
loaderContext.callback(
null,
descriptor.renderjs.content,
descriptor.renderjs.map
)
return
}
// styles
if (query.type === `style` && query.index != null) {
const style = descriptor.styles[query.index]
......
......@@ -81,7 +81,7 @@ function updateView () {
)
}
window.addEventListener('resize', updateView)
window.addEventListener('resize', updateView)
window.addEventListener('updateview', updateView)
function vdSync ({
......@@ -119,7 +119,9 @@ function getData (id, name) {
function getChangeData (id, name) {
try {
const value = this.$r[id][name]
this.$set(this.wxsProps, name.replace('change:', ''), value)
const wxsPropName = name.replace('change:', '')
this[wxsPropName] = value
this.$set(this.wxsProps, wxsPropName, value)
return value
} catch (e) {
console.error(this.$options.__file + `:[${this._$id}]$r[${id}][${name}] is undefined`)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册