Skip to content

Commit 692d88a

Browse files
committed
#172: Rebuild distributable package
1 parent edbed21 commit 692d88a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

dist/GoogleApiComponent.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,18 @@
165165
}, {
166166
key: 'initialize',
167167
value: function initialize(options) {
168+
// Avoid race condition: remove previous 'load' listener
169+
if (this.unregisterLoadHandler) {
170+
this.unregisterLoadHandler();
171+
this.unregisterLoadHandler = null;
172+
}
173+
168174
// Load cache factory
169175
var createCache = options.createCache || defaultCreateCache;
170176

171177
// Build script
172178
this.scriptCache = createCache(options);
173-
this.scriptCache.google.onLoad(this.onLoad.bind(this));
179+
this.unregisterLoadHandler = this.scriptCache.google.onLoad(this.onLoad.bind(this));
174180

175181
// Store information about loading container
176182
this.LoadingContainer = options.LoadingContainer || DefaultLoadingContainer;

dist/lib/ScriptCache.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,27 @@
2525

2626
Cache._onLoad = function (key) {
2727
return function (cb) {
28+
var registered = true;
29+
30+
function unregister() {
31+
registered = false;
32+
}
33+
2834
var stored = scriptMap.get(key);
35+
2936
if (stored) {
3037
stored.promise.then(function () {
31-
stored.error ? cb(stored.error) : cb(null, stored);
38+
if (registered) {
39+
stored.error ? cb(stored.error) : cb(null, stored);
40+
}
41+
3242
return stored;
3343
});
3444
} else {
3545
// TODO:
3646
}
47+
48+
return unregister;
3749
};
3850
};
3951

0 commit comments

Comments
 (0)