Skip to content

Commit 41e0fb1

Browse files
committed
Made ScriptCache isomorphic friendly
1 parent eaf64d8 commit 41e0fb1

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/utils/scriptCache.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
let counter = 0;
22
let scriptMap = new Map();
33

4-
export const ScriptCache = (function(global) {
5-
return function ScriptCache (scripts) {
4+
export const ScriptCache = (function (global) {
5+
'use strict';
6+
const ScriptCache = function (scripts) {
67
const Cache = {}
78

89
Cache._onLoad = function (key) {
@@ -97,6 +98,21 @@ export const ScriptCache = (function(global) {
9798

9899
return Cache;
99100
}
100-
})(window)
101+
102+
// AMD support
103+
if (typeof define === 'function' && define.amd) {
104+
define(function () { return ScriptCache; });
105+
// CommonJS and Node.js module support.
106+
} else if (typeof exports !== 'undefined') {
107+
// Support Node.js specific `module.exports` (which can be a function)
108+
if (typeof module !== 'undefined' && module.exports) {
109+
exports = module.exports = ScriptCache;
110+
}
111+
// But always support CommonJS module 1.1.1 spec (`exports` cannot be a function)
112+
exports.ScriptCache = ScriptCache;
113+
} else {
114+
global.ScriptCache = ScriptCache;
115+
}
116+
})(this);
101117

102118
export default ScriptCache;

src/utils/scriptCache.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {expect} from 'chai'
22
import sinon from 'sinon'
3-
import {ScriptCache} from './ScriptCache'
3+
import ScriptCache from './ScriptCache'
44

55
describe('Cache', () => {
66
let cache = [];

0 commit comments

Comments
 (0)