From 3ecbc7899189c50e0612fb7fc7d018cce8e88f79 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 8 Jan 2020 18:46:51 +0800 Subject: [PATCH] fix(v3): detect nested value changes inside props --- packages/uni-app-plus/dist/index.v3.js | 43 ++++++++++++----- .../uni-app-plus/dist/service.runtime.esm.js | 48 +++++++++++++++++++ 2 files changed, 79 insertions(+), 12 deletions(-) diff --git a/packages/uni-app-plus/dist/index.v3.js b/packages/uni-app-plus/dist/index.v3.js index bd35a8c80..7257a1e72 100644 --- a/packages/uni-app-plus/dist/index.v3.js +++ b/packages/uni-app-plus/dist/index.v3.js @@ -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); diff --git a/packages/uni-app-plus/dist/service.runtime.esm.js b/packages/uni-app-plus/dist/service.runtime.esm.js index 80d9fd59c..556e2cd35 100644 --- a/packages/uni-app-plus/dist/service.runtime.esm.js +++ b/packages/uni-app-plus/dist/service.runtime.esm.js @@ -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 ]; -- GitLab