77 global . Page = global . Page || Page ;
88 global . Component = global . Component || Component ;
99 global . getApp = global . getApp || getApp ;
10+
11+ if ( typeof wx !== 'undefined' ) {
12+ global . mpvue = wx ;
13+ global . mpvuePlatform = 'wx' ;
14+ } else if ( typeof swan !== 'undefined' ) {
15+ global . mpvue = swan ;
16+ global . mpvuePlatform = 'swan' ;
17+ }
1018} catch ( e ) { }
1119
1220( function ( global , factory ) {
@@ -847,8 +855,6 @@ function observe (value, asRootData, key) {
847855 ! value . _isVue
848856 ) {
849857 ob = new Observer ( value , key ) ;
850- ob . __keyPath = ob . __keyPath ? ob . __keyPath : { } ;
851- ob . __keyPath [ key ] = true ;
852858 }
853859 if ( asRootData && ob ) {
854860 ob . vmCount ++ ;
@@ -873,8 +879,6 @@ function defineReactive$$1 (
873879 return
874880 }
875881
876- // TODO: 先试验标记一下 keyPath
877-
878882 // cater for pre-defined getter/setters
879883 var getter = property && property . get ;
880884 var setter = property && property . set ;
@@ -914,8 +918,12 @@ function defineReactive$$1 (
914918 }
915919 childOb = ! shallow && observe ( newVal , undefined , key ) ;
916920 dep . notify ( ) ;
917- obj . __keyPath = obj . __keyPath ? obj . __keyPath : { } ;
918- obj . __keyPath [ key ] = true ;
921+
922+ var ob = obj . __ob__ ;
923+ if ( ! ob . __keyPath ) {
924+ def ( ob , '__keyPath' , { } , false ) ;
925+ }
926+ ob . __keyPath [ key ] = true ;
919927 }
920928 } ) ;
921929}
@@ -948,8 +956,10 @@ function set (target, key, val) {
948956 return val
949957 }
950958 defineReactive$$1 ( ob . value , key , val ) ;
951- // Vue.set 添加对象属性,渲染时候把val传给小程序渲染
952- target . __keyPath = target . __keyPath ? target . __keyPath : { } ;
959+ // Vue.set 添加对象属性,渲染时候把 val 传给小程序渲染
960+ if ( ! target . __keyPath ) {
961+ def ( target , '__keyPath' , { } , false ) ;
962+ }
953963 target . __keyPath [ key ] = true ;
954964 ob . dep . notify ( ) ;
955965 return val
@@ -978,8 +988,10 @@ function del (target, key) {
978988 if ( ! ob ) {
979989 return
980990 }
981- target . __keyPath = target . __keyPath ? target . __keyPath : { } ;
982- // Vue.del 删除对象属性,渲染时候把这个属性设置为undefined
991+ if ( ! target . __keyPath ) {
992+ def ( target , '__keyPath' , { } , false ) ;
993+ }
994+ // Vue.del 删除对象属性,渲染时候把这个属性设置为 undefined
983995 target . __keyPath [ key ] = 'del' ;
984996 ob . dep . notify ( ) ;
985997}
@@ -4961,6 +4973,8 @@ function callHook$1 (vm, hook, params) {
49614973 var handlers = vm . $options [ hook ] ;
49624974 if ( hook === 'onError' && handlers ) {
49634975 handlers = [ handlers ] ;
4976+ } else if ( hook === 'onPageNotFound' && handlers ) {
4977+ handlers = [ handlers ] ;
49644978 }
49654979
49664980 var ret ;
@@ -5176,6 +5190,10 @@ function initMP (mpType, next) {
51765190
51775191 onError : function onError ( err ) {
51785192 callHook$1 ( rootVueVM , 'onError' , err ) ;
5193+ } ,
5194+
5195+ onPageNotFound : function onPageNotFound ( err ) {
5196+ callHook$1 ( rootVueVM , 'onPageNotFound' , err ) ;
51795197 }
51805198 } ) ;
51815199 } else if ( mpType === 'component' ) {
@@ -5343,13 +5361,14 @@ function getDeepData (keyList, viewData) {
53435361 }
53445362 }
53455363}
5346- function compareAndSetDeepData ( key , newData , vm , data ) {
5364+
5365+ function compareAndSetDeepData ( key , newData , vm , data , forceUpdate ) {
53475366 // 比较引用类型数据
53485367 try {
53495368 var keyList = key . split ( '.' ) ;
5350- // page.__viewData__老版小程序不存在,使用mpvue里绑的data比对
5369+ // page.__viewData__老版小程序不存在,使用mpvue里绑的data比对
53515370 var oldData = getDeepData ( keyList , vm . $root . $mp . page . data ) ;
5352- if ( oldData === null || JSON . stringify ( oldData ) !== JSON . stringify ( newData ) ) {
5371+ if ( oldData === null || JSON . stringify ( oldData ) !== JSON . stringify ( newData ) || forceUpdate ) {
53535372 data [ key ] = newData ;
53545373 }
53555374 } catch ( e ) {
@@ -5369,7 +5388,7 @@ function minifyDeepData (rootKey, originKey, vmData, data, _mpValueSet, vm) {
53695388 try {
53705389 if ( vmData instanceof Array ) {
53715390 // 数组
5372- compareAndSetDeepData ( rootKey + '.' + originKey , vmData , vm , data ) ;
5391+ compareAndSetDeepData ( rootKey + '.' + originKey , vmData , vm , data , true ) ;
53735392 } else {
53745393 // Object
53755394 var _keyPathOnThis = { } ; // 存储这层对象的keyPath
@@ -5431,20 +5450,19 @@ function diffData (vm, data) {
54315450 } ) ;
54325451 // console.log(rootKey)
54335452
5434- // 值类型变量不考虑优化,还是直接更新
5435- var __keyPathOnThis = vmData . __keyPath || vm . __keyPath || { } ;
5453+ // 值类型变量不考虑优化,还是直接更新
5454+ var __keyPathOnThis = getDeepData ( [ '__ob__' , ' __keyPath' ] , vmData ) || getDeepData ( [ '__ob__' , ' __keyPath' ] , vm ) || { } ;
54365455 delete vm . __keyPath ;
54375456 delete vmData . __keyPath ;
54385457 delete vmProps . __keyPath ;
54395458 if ( vm . _mpValueSet === 'done' ) {
54405459 // 第二次赋值才进行缩减操作
54415460 Object . keys ( vmData ) . forEach ( function ( vmDataItemKey ) {
54425461 if ( vmData [ vmDataItemKey ] instanceof Object ) {
5443- // 引用类型
5444- if ( vmDataItemKey === '__keyPath' ) { return }
5462+ // 引用类型
54455463 minifyDeepData ( rootKey , vmDataItemKey , vmData [ vmDataItemKey ] , data , vm . _mpValueSet , vm ) ;
5446- } else if ( vmData [ vmDataItemKey ] !== undefined ) {
5447- // _data上的值属性只有要更新的时候才赋值
5464+ } else if ( vmData [ vmDataItemKey ] !== undefined ) {
5465+ // _data上的值属性只有要更新的时候才赋值
54485466 if ( __keyPathOnThis [ vmDataItemKey ] === true ) {
54495467 data [ rootKey + '.' + vmDataItemKey ] = vmData [ vmDataItemKey ] ;
54505468 }
@@ -5454,9 +5472,8 @@ function diffData (vm, data) {
54545472 Object . keys ( vmProps ) . forEach ( function ( vmPropsItemKey ) {
54555473 if ( vmProps [ vmPropsItemKey ] instanceof Object ) {
54565474 // 引用类型
5457- if ( vmPropsItemKey === '__keyPath' ) { return }
54585475 minifyDeepData ( rootKey , vmPropsItemKey , vmProps [ vmPropsItemKey ] , data , vm . _mpValueSet , vm ) ;
5459- } else if ( vmProps [ vmPropsItemKey ] !== undefined ) {
5476+ } else if ( vmProps [ vmPropsItemKey ] !== undefined ) {
54605477 data [ rootKey + '.' + vmPropsItemKey ] = vmProps [ vmPropsItemKey ] ;
54615478 }
54625479 // _props上的值属性只有要更新的时候才赋值
@@ -5471,14 +5488,14 @@ function diffData (vm, data) {
54715488 Object . keys ( vmComputedWatchers ) . forEach ( function ( computedItemKey ) {
54725489 data [ rootKey + '.' + computedItemKey ] = vm [ computedItemKey ] ;
54735490 } ) ;
5474- // 更新的时候要删除$root.0:{},否则会覆盖原正确数据
5491+ // 更新的时候要删除$root.0:{},否则会覆盖原正确数据
54755492 delete data [ rootKey ] ;
54765493 }
54775494 if ( vm . _mpValueSet === undefined ) {
5478- // 第一次设置数据成功后,标记位置true,再更新到这个节点如果没有keyPath数组认为不需要更新
5495+ // 第一次设置数据成功后,标记位置true,再更新到这个节点如果没有keyPath数组认为不需要更新
54795496 vm . _mpValueSet = 'done' ;
54805497 }
5481- if ( Vue$3 . config . devtools ) {
5498+ if ( Vue$3 . config . _mpTrace ) {
54825499 // console.log('更新VM节点', vm)
54835500 // console.log('实际传到Page.setData数据', data)
54845501 diffLog ( data ) ;
@@ -5624,7 +5641,6 @@ function getPage (vm) {
56245641}
56255642
56265643// 优化js变量动态变化时候引起全量更新
5627-
56285644// 优化每次 setData 都传递大量新数据
56295645function updateDataToMP ( ) {
56305646 var page = getPage ( this ) ;
@@ -5633,9 +5649,7 @@ function updateDataToMP () {
56335649 }
56345650
56355651 var data = formatVmData ( this ) ;
5636-
56375652 diffData ( this , data ) ;
5638-
56395653 throttleSetData ( page . setData . bind ( page ) , data ) ;
56405654}
56415655
@@ -5743,6 +5757,8 @@ function getWebEventByMP (e) {
57435757 return event
57445758}
57455759
5760+
5761+ var KEY_SEP$1 = '_' ;
57465762function handleProxyWithVue ( e ) {
57475763 var rootVueVM = this . $root ;
57485764 var type = e . type ;
@@ -5752,7 +5768,7 @@ function handleProxyWithVue (e) {
57525768 var dataset = ref . dataset ; if ( dataset === void 0 ) dataset = { } ;
57535769 var comkey = dataset . comkey ; if ( comkey === void 0 ) comkey = '' ;
57545770 var eventid = dataset . eventid ;
5755- var vm = getVM ( rootVueVM , comkey . split ( ',' ) ) ;
5771+ var vm = getVM ( rootVueVM , comkey . split ( KEY_SEP$1 ) ) ;
57565772
57575773 if ( ! vm ) {
57585774 return
0 commit comments