-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from HuolalaTech/feat/mp-sys
Feat/mp sys 小程序系统信息面板
- Loading branch information
Showing
26 changed files
with
533 additions
and
548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Wrap the mp api to smooth the platform differences, for internal usage only. | ||
// This api can be modified by mp sdk implementor. | ||
// This api should be passed through PageSpy instance to avoid esm multi-pack. | ||
|
||
import { MPSDK } from '../types'; | ||
|
||
let mpSDK: any; | ||
|
||
// the origin mp sdk, used for hacking | ||
let originMPSDK: any; | ||
|
||
if (typeof Proxy !== 'undefined') { | ||
mpSDK = new Proxy( | ||
{}, | ||
{ | ||
get(target, p: string) { | ||
if (platformAPI[p]) { | ||
return platformAPI[p]; | ||
} | ||
if (originMPSDK[p]) { | ||
return originMPSDK[p]; | ||
} else { | ||
console.error('The mp sdk does not support the api:', p); | ||
} | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
// for API compatibility | ||
// this api can be modified by mp sdk implementor, to smoothy the platform differences. | ||
export const platformAPI: Record<string, any> = {}; | ||
export const getMPSDK = () => { | ||
if (!mpSDK) { | ||
throw Error('the mp sdk is not set'); | ||
} | ||
return mpSDK as MPSDK; | ||
}; | ||
|
||
export const getOriginMPSDK = () => originMPSDK as MPSDK; | ||
|
||
export const setMPSDK = (SDK: MPSDK) => { | ||
originMPSDK = SDK; | ||
if (typeof Proxy === 'undefined') { | ||
mpSDK = { | ||
...SDK, | ||
...platformAPI, | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.