Skip to content

Commit bc08f37

Browse files
committed
rename to Scratch.external, remove some unnecessary methods
1 parent 86be09c commit bc08f37

File tree

2 files changed

+10
-41
lines changed

2 files changed

+10
-41
lines changed

src/extension-support/tw-extension-api-common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ const BlockType = require('./block-type');
33
const BlockShape = require('./tw-block-shape');
44
const TargetType = require('./target-type');
55
const Cast = require('../util/cast');
6-
const importDependency = require('./tw-import-dependency');
6+
const external = require('./tw-external');
77

88
const Scratch = {
99
ArgumentType,
1010
BlockType,
1111
BlockShape,
1212
TargetType,
1313
Cast,
14-
importDependency
14+
external
1515
};
1616

1717
module.exports = Scratch;

src/extension-support/tw-import-dependency.js renamed to src/extension-support/tw-external.js

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,67 +19,36 @@ const checkURL = url => {
1919
}
2020
};
2121

22-
const importDependency = {};
22+
const dependency = {};
2323

2424
/**
2525
* @param {string} url
2626
* @template T
2727
* @returns {Promise<T>}
2828
*/
29-
importDependency.asModule = url => {
29+
dependency.import = url => {
3030
checkURL(url);
3131
// Need to specify webpackIgnore so that webpack compiles this directly to a call to import()
32-
// instead of trying making it try to use the webpack dependency system.
32+
// instead of trying making it try to use the webpack import system.
3333
return import(/* webpackIgnore: true */ url);
3434
};
3535

3636
/**
3737
* @param {string} url
38-
* @returns {Promise<Response>|Response}
38+
* @returns {Promise<Response>}
3939
*/
40-
importDependency.asFetch = url => {
40+
dependency.fetch = url => {
4141
checkURL(url);
4242
return fetch(url);
4343
};
4444

45-
/**
46-
* @param {string} url
47-
* @returns {Promise<string>|string}
48-
*/
49-
importDependency.asDataURL = async url => {
50-
checkURL(url);
51-
const res = await fetch(url);
52-
const blob = await res.blob();
53-
return new Promise((resolve, reject) => {
54-
const fr = new FileReader();
55-
fr.onload = () => resolve(fr.result);
56-
fr.onerror = () => reject(fr.error);
57-
fr.readAsDataURL(blob);
58-
});
59-
};
60-
61-
/**
62-
* @param {string} url
63-
* @returns {Promise<void>}
64-
*/
65-
importDependency.asScriptTag = url => {
66-
checkURL(url);
67-
return new Promise((resolve, reject) => {
68-
const script = document.createElement('script');
69-
script.onload = () => resolve();
70-
script.onerror = () => reject(new Error('Script error'));
71-
script.src = url;
72-
return script;
73-
});
74-
};
75-
7645
/**
7746
* @param {string} url
7847
* @param {string} returnExpression
7948
* @template T
80-
* @returns {Promise<T>|T}
49+
* @returns {Promise<T>}
8150
*/
82-
importDependency.asEval = async (url, returnExpression) => {
51+
dependency.evalAndReturn = async (url, returnExpression) => {
8352
checkURL(url);
8453

8554
const res = await fetch(url);
@@ -93,4 +62,4 @@ importDependency.asEval = async (url, returnExpression) => {
9362
return fn();
9463
};
9564

96-
module.exports = importDependency;
65+
module.exports = dependency;

0 commit comments

Comments
 (0)