Skip to content

Commit fbe0ceb

Browse files
committed
feat: loadJs/Css supports parallel
1 parent db5073a commit fbe0ceb

File tree

7 files changed

+32
-16
lines changed

7 files changed

+32
-16
lines changed

public/code/genji.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
await loadJs('https://unpkg.com/react-redux')
2-
await loadJs('https://unpkg.com/genjijs-umd/dist/index.min.js')
1+
await loadJs([
2+
'https://unpkg.com/[email protected]/dist/react-redux.js',
3+
'https://unpkg.com/[email protected]/dist/index.min.js',
4+
])
35

46
let { Provider, useSelector, useDispatch } = ReactRedux
57

public/code/index.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
- hello-world.jsx
21
- vue-at-gh119.js
32
- vue-at-element-2.x-input.js
43
- vue-at-element-1.x-input.js
@@ -12,3 +11,4 @@
1211
- react-editor-sizing.jsx
1312
- react-editor.jsx
1413
- use-model.jsx
14+
- hello-world.jsx

public/code/react-editor-sizing.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
await loadJs('https://unpkg.com/react-editor')
2-
await loadJs('https://unpkg.com/react-drag-sizing')
1+
await loadJs([
2+
'https://unpkg.com/react-editor',
3+
'https://unpkg.com/react-drag-sizing',
4+
])
35

46
let { Editor } = ReactEditor
57
let { DragSizing } = ReactDragSizing

public/code/use-model.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
await loadJs('https://unpkg.com/immer')
2-
await loadJs('https://unpkg.com/react-editor')
1+
await loadJs([
2+
'https://unpkg.com/[email protected]/dist/immer.umd.production.min.js',
3+
'https://unpkg.com/[email protected]/dist/index.js',
4+
])
35

46
let { produce } = immer
57
let { Button } = Antd

public/code/vue-threejs.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// await loadJs('https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js')
2-
await loadJs('https://unpkg.com/[email protected]/dist/vue.min.js')
3-
4-
// await loadJs('https://unpkg.com/three@0.81.2/build/three.min.js')
5-
await loadJs('https://unpkg.com/[email protected]/build/three.min.js')
1+
await loadJs([
2+
'https://unpkg.com/[email protected]/dist/vue.min.js',
3+
// 'https://unpkg.com/[email protected]/build/three.min.js',
4+
'https://unpkg.com/three@0.115.0/build/three.min.js',
5+
])
66

77
// await loadJs('https://unpkg.com/[email protected]/lib/VueThreejs.umd.min.js')
88
await loadJs('https://unpkg.com/[email protected]/lib/VueThreejs.umd.js')

src/gallery/Gallery.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ export let Gallery: React.FC = () => {
5252
onError={handleImageError}
5353
/>
5454
}
55-
onClick={() => {
56-
history.push(`/playground/${id}`);
55+
onClick={e => {
56+
if (e.metaKey) {
57+
window.open(`/#/playground/${id}`);
58+
} else {
59+
history.push(`/playground/${id}`);
60+
}
5761
}}
5862
>
5963
<Card.Meta

src/playground/util.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ export let loadJsForceUmd = async ({
4040
appendJs(code);
4141
};
4242

43-
export let loadJs = (url: string) => {
43+
export let loadJs = (url: string | string[]): Promise<void> => {
44+
if (Array.isArray(url)) {
45+
return Promise.all(url.map(loadJs)).then(() => undefined);
46+
}
4447
return new Promise((resolve, reject) => {
4548
let el = document.createElement('script');
4649
el.src = url;
@@ -54,7 +57,10 @@ export let loadJs = (url: string) => {
5457
});
5558
};
5659

57-
export let loadCss = (url: string) => {
60+
export let loadCss = (url: string | string[]): Promise<void> => {
61+
if (Array.isArray(url)) {
62+
return Promise.all(url.map(loadCss)).then(() => undefined);
63+
}
5864
return new Promise((resolve, reject) => {
5965
let el = document.createElement('link');
6066
el.rel = 'stylesheet';

0 commit comments

Comments
 (0)