-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ support dynamic append in multiple mode (#427)
* ✨ support dynamic append in multiple mode * 🎨 pretty code * 🎨 remove unused code
- Loading branch information
Showing
12 changed files
with
170 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>qiankun multiple demo</title> | ||
<style> | ||
body { | ||
width: 100vw; | ||
height: 100vh; | ||
display: flex; | ||
justify-content: space-around; | ||
align-items: center; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="react15">react loading...</div> | ||
<div id="vue">vue loading...</div> | ||
|
||
<script src="./multiple.js"></script> | ||
</body> | ||
</html> |
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,21 @@ | ||
import { loadMicroApp } from '../../es'; | ||
|
||
const app1 = loadMicroApp( | ||
{ name: 'react15', entry: '//localhost:7102', container: '#react15' }, | ||
{ | ||
singular: false, | ||
sandbox: { | ||
// strictStyleIsolation: true, | ||
}, | ||
}, | ||
); | ||
|
||
const app2 = loadMicroApp( | ||
{ name: 'vue', entry: '//localhost:7101', container: '#vue' }, | ||
{ | ||
singular: false, | ||
sandbox: { | ||
// strictStyleIsolation: true, | ||
}, | ||
}, | ||
); |
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
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,40 @@ | ||
/** | ||
* @author Kuitos | ||
* @since 2020-04-13 | ||
*/ | ||
|
||
import { isConstructable } from '../utils'; | ||
|
||
const boundValueSymbol = Symbol('bound value'); | ||
|
||
export function getTargetValue(target: any, value: any): any { | ||
/* | ||
仅绑定 !isConstructable && isCallable 的函数对象,如 window.console、window.atob 这类。目前没有完美的检测方式,这里通过 prototype 中是否还有可枚举的拓展方法的方式来判断 | ||
@warning 这里不要随意替换成别的判断方式,因为可能触发一些 edge case(比如在 lodash.isFunction 在 iframe 上下文中可能由于调用了 top window 对象触发的安全异常) | ||
*/ | ||
if (typeof value === 'function' && !isConstructable(value)) { | ||
if (value[boundValueSymbol]) { | ||
return value[boundValueSymbol]; | ||
} | ||
|
||
const boundValue = value.bind(target); | ||
// some callable function has custom fields, we need to copy the enumerable props to boundValue. such as moment function. | ||
Object.keys(value).forEach(key => (boundValue[key] = value[key])); | ||
Object.defineProperty(value, boundValueSymbol, { enumerable: false, value: boundValue }); | ||
return boundValue; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
const proxyGetterMap = new Map<WindowProxy, Record<PropertyKey, any>>(); | ||
|
||
export function getProxyPropertyGetter(proxy: WindowProxy, property: PropertyKey) { | ||
const getters = proxyGetterMap.get(proxy) || ({} as Record<string, any>); | ||
return getters[property as string]; | ||
} | ||
|
||
export function setProxyPropertyGetter(proxy: WindowProxy, property: PropertyKey, getter: () => any) { | ||
const prevGetters = proxyGetterMap.get(proxy) || {}; | ||
proxyGetterMap.set(proxy, { ...prevGetters, [property]: getter }); | ||
} |
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.
7d046d1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for website ready!
Built with commit 7d046d1
https://https://qiankun-qbhpxk29l.now.sh