Skip to content

Commit

Permalink
feat(core & build): support skipLaterCalc for computed
Browse files Browse the repository at this point in the history
  • Loading branch information
allen-zh committed Apr 17, 2019
1 parent 6b265c9 commit 6dcf61c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/mars-build/src/scripts/defaultConfig.js
Expand Up @@ -16,6 +16,7 @@ module.exports = function (target) {
],
designWidth: 750,
watch: ['src/**/*'],
framework: {},
modules: {
postcss: {
px2units: {
Expand Down
10 changes: 10 additions & 0 deletions packages/mars-build/src/scripts/gulpTasks.js
Expand Up @@ -99,6 +99,13 @@ function getTaskRuntime(config, options) {
const {dest: buildDest, source} = config;
let dest = getDestDir(config, options);
dest = dest + '/' + buildDest.coreDir;
let framework = JSON.stringify({});
try {
framework = JSON.stringify(config.framework || {});
} catch (e) {
throw new Error('config.framework must be plain Object');
}

return () => {
return gulp.src(source.runtime)
.pipe(changed(dest))
Expand All @@ -109,6 +116,9 @@ function getTaskRuntime(config, options) {
source = source.replace(
/process\.env\.NODE_ENV/g,
JSON.stringify(process.env.NODE_ENV || 'development')
).replace(
/process\.env\.MARS_CONFIG_FRAMEWORK/g,
framework
);
const ret = transform(source, {
plugins: [
Expand Down
19 changes: 11 additions & 8 deletions packages/mars-core/src/base/data.js
Expand Up @@ -12,6 +12,8 @@ import {mark, measure} from '../helper/perf';
import config from '../config';
import {getMpUpdatedCallbacks} from './api/mpNextTick';

const {framework = {}} = config;

function cleanKeyPath(vm) {
if (vm.__mpKeyPath) {
Object.keys(vm.__mpKeyPath).forEach(_key => {
Expand Down Expand Up @@ -55,14 +57,15 @@ export function setData(vm, $mp, isRoot = false) {
const computed = getChangedComputed(vm);
data = Object.assign(data, computed, changed);
// 如果后续数据更新 需要计算新增的实例上的 computed 值
// if (Object.keys(data).length > 0) {
// const allComputed = getAllComputed(vm);
// data = Object.keys(allComputed).length > 0
// ? Object.assign(data, {
// [isRoot ? 'rootComputed' : 'compComputed']: allComputed
// })
// : data;
// }
const skipLaterCalc = framework.computed && framework.computed.skipLaterCalc;
if (!skipLaterCalc && Object.keys(data).length > 0) {
const allComputed = getAllComputed(vm);
data = Object.keys(allComputed).length > 0
? Object.assign(data, {
[isRoot ? 'rootComputed' : 'compComputed']: allComputed
})
: data;
}
}

if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
Expand Down
3 changes: 2 additions & 1 deletion packages/mars-core/src/config.js
Expand Up @@ -5,5 +5,6 @@

export default {
performance: false,
debug: false
debug: false,
framework: process.env.MARS_CONFIG_FRAMEWORK
};

0 comments on commit 6dcf61c

Please sign in to comment.