提交 3ecbc789 编写于 作者: fxy060608's avatar fxy060608

fix(v3): detect nested value changes inside props

上级 11e2bc73
......@@ -8962,14 +8962,14 @@ var serviceContext = (function () {
'pause',
'stop',
'ended',
'timeupdate',
'timeUpdate',
'error',
'waiting',
'seeking',
'seeked'
];
const props = [
const props = [
{
name: 'src',
cache: true
......@@ -9022,7 +9022,7 @@ var serviceContext = (function () {
this._callbacks = {};
this._options = {};
eventNames.forEach(name => {
this._callbacks[name] = [];
this._callbacks[name.toLowerCase()] = [];
});
props.forEach(item => {
const name = item.name;
......@@ -9056,11 +9056,12 @@ var serviceContext = (function () {
this._operate('stop');
}
seek (position) {
this._operate('play', {
currentTime: position
this._operate('seek', {
currentTime: position * 1e3
});
}
destroy () {
clearInterval(this.__timing);
invokeMethod('destroyAudioInstance', {
audioId: this.id
});
......@@ -9076,6 +9077,7 @@ var serviceContext = (function () {
eventNames.forEach(item => {
const name = item[0].toUpperCase() + item.substr(1);
item = item.toLowerCase();
InnerAudioContext.prototype[`on${name}`] = function (callback) {
this._callbacks[item].push(callback);
};
......@@ -9088,6 +9090,17 @@ var serviceContext = (function () {
};
});
function emit (audio, state, errMsg, errCode) {
audio._callbacks[state].forEach(callback => {
if (typeof callback === 'function') {
callback(state === 'error' ? {
errMsg,
errCode
} : {});
}
});
}
onMethod('onAudioStateChange', ({
state,
audioId,
......@@ -9095,14 +9108,20 @@ var serviceContext = (function () {
errCode
}) => {
const audio = innerAudioContexts[audioId];
audio && audio._callbacks[state].forEach(callback => {
if (typeof callback === 'function') {
callback(state === 'error' ? {
errMsg,
errCode
} : {});
if (audio) {
emit(audio, state, errMsg, errCode);
if (state === 'play') {
const oldCurrentTime = audio.currentTime;
audio.__timing = setInterval(() => {
const currentTime = audio.currentTime;
if (currentTime !== oldCurrentTime) {
emit(audio, 'timeupdate');
}
}, 200);
} else if (state === 'pause' || state === 'stop' || state === 'error') {
clearInterval(audio.__timing);
}
});
}
});
const innerAudioContexts = Object.create(null);
......
......@@ -6642,6 +6642,53 @@ var baseModules = [
directives
];
/* */
function updateWxsProps(oldVnode, vnode) {
if (
isUndef(oldVnode.data.wxsProps) &&
isUndef(vnode.data.wxsProps)
) {
return
}
var oldWxsWatches = oldVnode.$wxsWatches;
var wxsPropsKey = Object.keys(vnode.data.wxsProps);
if (!oldWxsWatches && !wxsPropsKey.length) {
return
}
if (!oldWxsWatches) {
oldWxsWatches = {};
}
var wxsProps = vnode.data.wxsProps;
vnode.$wxsWatches = {};
Object.keys(wxsProps).forEach(function (prop) {
var watchProp = wxsProps[prop];
vnode.$wxsWatches[prop] = oldWxsWatches[prop] || vnode.context.$watch(watchProp, function() {
this.$forceUpdate();
}, {
deep: true
});
});
Object.keys(oldWxsWatches).forEach(function (oldName) {
if (!vnode.$wxsWatches[oldName]) {
oldWxsWatches[oldName]();
delete oldWxsWatches[oldName];
}
});
}
var wxs = {
create: updateWxsProps,
update: updateWxsProps
};
function parseDataset(attrs) {
var dataset = Object.create(null);
Object.keys(attrs).forEach(function (name) {
......@@ -6765,6 +6812,7 @@ var events = {
};
var platformModules = [
wxs,
attrs,
events
];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册