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

fix(v3): detect nested value changes inside props

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