Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Harmony-Hybrid】优化Taro Storage缓存,解决跨Web容器修改Storage后缓存不更新 #16263

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions examples/mini-program-example/src/pages/index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,20 @@ export default function Index() {
</Button>
<Button
onClick={()=>{
nativeApi.harmonyNavigateTo({
indexHtmlPath: '/spa/new/index.html',
taroPath: 'pages/performance/index/index'
Taro.navigateTo({
url: 'pages/harmony-hybrid/mix-router/home/index'
})
}}>
多实例(多SPA跳转):性能列表页
多实例及混合路由测试页
</Button>
<Button
onClick={()=>{
nativeApi.harmonyNavigateTo({
nativeApi.navigateToTaroHybrid({
indexHtmlPath: '/spa/new/index.html',
taroPath: 'pages/api/index/index'
taroPath: '/pages/index/index'
})
}}>
单实例(单SPA):接口列表页
多实例(单SPA):首页
</Button>
</View>
)
Expand Down
13 changes: 7 additions & 6 deletions examples/mini-program-example/src/util/nativeApi.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// @ts-ignore
const decorator = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: true }) || (target => target)
const sync = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: true }) || (target => target)

// @proxyClassSign('')
class NativeApi {
// @ts-ignore
@decorator
harmonyNavigateTo(options: any) {
return options
}
@sync
navigateToTaroHybrid(_options: any) {}


@sync
navigateToNative(_options: any){}
}

const nativeApi = new NativeApi()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,7 @@
"TARO_ENV": true,
"USER_DATA_PATH": true
},
"exitMiniProgram": {
"object": {
"url": true,
"events": true
}
},
"exitMiniProgram": true,
"exitVoIPChat": false,
"faceDetect": false,
"faceVerifyForPay": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import {timeLog} from "./NativeApiLog";
import { syncApiCache } from './harmony-native/ApiCache'
import { asyncAndNotRelease, asyncAndRelease, syncAndRelease } from './harmony-native/ApiDecorator'
import { asyncAndNotRelease, asyncAndRelease, syncAndNotRelease, syncAndRelease } from './harmony-native/ApiDecorator'
import { storageCacheAndSyncProxy } from './harmony-native/StorageCacheAndSyncProxy'
import { NativeDataChangeListener, SyncCacheProxyHandler } from './NativeApiSyncCacheProxy'

Expand Down Expand Up @@ -627,6 +627,12 @@ export class NativeApi {
exitMiniProgram (option?: any): any {
return option
}

@(syncAndNotRelease)
onStorageStatusChange (_options: any): void {}

@(syncAndNotRelease)
offStorageStatusChange (_options: any): void {}
}

export interface Status {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export const syncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: true }) || (target => target)

// @ts-ignore
// const syncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: false }) || (target => target)
export const syncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: false }) || (target => target)

// @ts-ignore
export const asyncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: true, autoRelease: true }) || (target => target)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const TYPE_STORAGE_UPDATE_EVENT_CLEAR = 'TYPE_STORAGE_UPDATE_EVENT_CLEAR'
class ProxyHandler {
private cacheMap: Map<any, any>
private pageHasShowed: boolean = false
Expand Down Expand Up @@ -28,6 +29,14 @@ class ProxyHandler {
})
}, 2000)
})

native.onStorageStatusChange((type: string, key: string) => {
if (type === TYPE_STORAGE_UPDATE_EVENT_CLEAR) {
this.cacheMap.clear()
} else {
this.cacheMap.delete(key)
}
})
}

get (target, propKey, receiver) {
Expand Down
Loading