Skip to content

Commit

Permalink
Merge pull request #171 from liamcmitchell-sc/defer-default
Browse files Browse the repository at this point in the history
Defer worker creation
  • Loading branch information
catdad authored Jan 26, 2022
2 parents 4a8ea77 + 8964192 commit 3d040ef
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/confetti.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,21 @@
return fire;
}

module.exports = confettiCannon(null, { useWorker: true, resize: true });
// Make default export lazy to defer worker creation until called.
var defaultFire;
function getDefaultFire() {
if (!defaultFire) {
defaultFire = confettiCannon(null, { useWorker: true, resize: true });
}
return defaultFire;
}

module.exports = function() {
return getDefaultFire().apply(this, arguments);
};
module.exports.reset = function() {
getDefaultFire().reset();
};
module.exports.create = confettiCannon;
}((function () {
if (typeof window !== 'undefined') {
Expand Down

0 comments on commit 3d040ef

Please sign in to comment.