Skip to content

Commit 6178535

Browse files
committed
chore(common): PAYPAL-4550 added ability to reload script by passing an addition parameter
1 parent 65c98b3 commit 6178535

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/script-loader.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ describe('ScriptLoader', () => {
6262
.toEqual(false);
6363
});
6464

65+
it('reload existing script', async () => {
66+
await loader.loadScript('https://code.jquery.com/jquery-3.2.1.min.js');
67+
await loader.loadScript('https://code.jquery.com/jquery-3.2.1.min.js', undefined, true);
68+
69+
expect(document.body.appendChild)
70+
.toHaveBeenCalledTimes(2);
71+
});
72+
6573
it('resolves promise if script is loaded', async () => {
6674
const output = await loader.loadScript('https://code.jquery.com/jquery-3.2.1.min.js');
6775

src/script-loader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export default class ScriptLoader {
2727
private _requestSender: RequestSender
2828
) {}
2929

30-
loadScript(src: string, options?: LoadScriptOptions): Promise<void> {
31-
if (!this._scripts[src]) {
30+
loadScript(src: string, options?: LoadScriptOptions, reloadScript?: boolean): Promise<void> {
31+
if (!this._scripts[src] || !!this._scripts[src] && reloadScript) {
3232
this._scripts[src] = new Promise((resolve, reject) => {
3333
const script = document.createElement('script') as LegacyHTMLScriptElement;
3434
const { async = false, attributes = {} } = options || {};

0 commit comments

Comments
 (0)