Skip to content

Commit

Permalink
fix: Merge branch 'master' into fix/span_label_in_alipay
Browse files Browse the repository at this point in the history
  • Loading branch information
elcarim5efil committed Nov 25, 2020
2 parents f7ea83e + 1c3732e commit 093233a
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 7 deletions.
16 changes: 13 additions & 3 deletions dist/megalo.mp.esm.js
Expand Up @@ -5129,7 +5129,7 @@ try {
}

function updateMPData (type, data, vnode) {
var obj;
var obj, obj$1;

if ( type === void 0 ) type = HOLDER_TYPE_VARS.text;
var vm = this;
Expand All @@ -5148,12 +5148,22 @@ try {

var curValue = getValue(vm.$mp.page.data, dataPaths);

// fix: 在设置 a.1 时,头条小程序会把 a 变成数组,导致后续的 a.b 设置失败
// 通过强制加一个字符串 key,将 holderVar 变成对象
if (vm.$mp.platform === 'toutiao') {
var convertObjectPaths = [ROOT_DATA_VAR, vmId, holderVar, '_obj'];
var convertObjectPathStr = convertObjectPaths.join('.');
if (!getValue(vm.$mp.page.data, convertObjectPaths)) {
vm.$mp._update(( obj = {}, obj[convertObjectPathStr] = true, obj ));
}
}

/* istanbul ignore else */
if (isDef(hid)) {
var isDeepEqual = deepEqual(curValue, data);
/* istanbul ignore else */
if (!isDeepEqual || vm.$mp._shouldUpdateBuffer(dataPathStr, data)) {
vm.$mp._update(( obj = {}, obj[dataPathStr] = data, obj ));
vm.$mp._update(( obj$1 = {}, obj$1[dataPathStr] = data, obj$1 ));
}
}
}
Expand Down Expand Up @@ -7531,7 +7541,7 @@ try {

/* */

Vue.megaloVersion = '0.10.3-1';
Vue.megaloVersion = '0.10.3';

return Vue;

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "megalo",
"version": "0.10.3-1",
"version": "0.10.3",
"description": "Reactive, component-oriented view layer for modern web interfaces.",
"main": "dist/megalo.mp.esm.js",
"module": "dist/megalo.mp.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/megalo-template-compiler/build.js
Expand Up @@ -5024,7 +5024,7 @@ var eventTypeMap$2 = {
CalloutTap: ['callouttap'],
ControlTap: ['controltap'],
RegionChange: ['regionchange'],
Message: ['message'],
Messag: ['message'],
PlusClick: ['plusclick'],
TabClick: ['tabclick'],
CardClick: ['cardclick'],
Expand Down
2 changes: 1 addition & 1 deletion packages/megalo-template-compiler/package.json
@@ -1,6 +1,6 @@
{
"name": "@megalo/template-compiler",
"version": "0.10.3-1",
"version": "0.10.3",
"description": "megalo template compiler for Vue",
"main": "index.js",
"repository": {
Expand Down
12 changes: 12 additions & 0 deletions src/platforms/mp/runtime/instance/update.js
Expand Up @@ -61,6 +61,18 @@ export function updateMPData (type = HOLDER_TYPE_VARS.text, data, vnode) {

const curValue = getValue(vm.$mp.page.data, dataPaths)

// fix: 在设置 a.1 时,头条小程序会把 a 变成数组,导致后续的 a.b 设置失败
// 通过强制加一个字符串 key,将 holderVar 变成对象
if (vm.$mp.platform === 'toutiao') {
const convertObjectPaths = [ROOT_DATA_VAR, vmId, holderVar, '_obj']
const convertObjectPathStr = convertObjectPaths.join('.')
if (!getValue(vm.$mp.page.data, convertObjectPaths)) {
vm.$mp._update({
[convertObjectPathStr]: true
})
}
}

/* istanbul ignore else */
if (isDef(hid)) {
const isDeepEqual = deepEqual(curValue, data)
Expand Down
3 changes: 2 additions & 1 deletion test/mp/helpers/index.js
Expand Up @@ -12,7 +12,8 @@ initMPEnvironment()
const platformAPI = {
wechat: 'wx',
alipay: 'my',
swan: 'swan'
swan: 'swan',
toutiao: 'tt'
}
export function setMPPlatform (platform) {
if (platformAPI[platform]) {
Expand Down
46 changes: 46 additions & 0 deletions test/mp/runtime/platform/toutiao.spec.js
@@ -0,0 +1,46 @@
import {
resetVue,
createPage,
setMPPlatform,
resetMPPlatform
} from '../../helpers'

describe('toutiao', () => {
it('should get platform from $mp', () => {
resetVue()
setMPPlatform('toutiao')

const pageOptions = {
template: `<div></div>`,
mpType: 'page'
}

const { vm } = createPage(pageOptions)

expect(vm.$mp.platform).toBe('toutiao')

resetMPPlatform()
})

it('should set obj convery flag in toutiao', () => {
resetVue()
setMPPlatform('toutiao')

const pageOptions = {
template: `<div>
<div v-for="item in list">{{item}}</div>
</div>`,
mpType: 'page',
data: {
list: [1, 2, 3]
}
}

const { vm } = createPage(pageOptions)

expect(vm.$mp.platform).toBe('toutiao')
expect(vm.$mp.page.data.$root[0].h._obj).toBeTruthy();

resetMPPlatform()
})
})
22 changes: 22 additions & 0 deletions test/mp/runtime/platform/wechat.spec.js
Expand Up @@ -21,4 +21,26 @@ describe('wechat', () => {

resetMPPlatform()
})

it('should not set obj convery flag in wechat', () => {
resetVue()
setMPPlatform('wechat')

const pageOptions = {
template: `<div>
<div v-for="item in list">{{item}}</div>
</div>`,
mpType: 'page',
data: {
list: [1, 2, 3]
}
}

const { vm } = createPage(pageOptions)

expect(vm.$mp.platform).toBe('wechat')
expect(vm.$mp.page.data.$root[0].h._obj).toBeUndefined();

resetMPPlatform()
})
})

0 comments on commit 093233a

Please sign in to comment.