Skip to content

Commit

Permalink
fix preload bugs (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuuno, Hibiki authored and joeyklee committed Mar 15, 2019
1 parent fc311e3 commit 7a51432
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/utils/p5PreloadHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ export default function registerPreload(obj) {
const fn = obj[key];

preloadFn[key] = function preloads(...args) {
return fn.apply(obj, [...args, function doingPreloads() {
let originCallback = null;
let argLen = args.length;
if (typeof args[argLen - 1] === 'function') {
// find callback function attached
originCallback = args[argLen - 1];
argLen -= 1;
}
return fn.apply(obj, [...args.slice(0, argLen), function doingPreloads() {
const targetPreloadFn = '_decrementPreload';
try {
if (originCallback) originCallback();
} catch (err) {
console.error(err);
}
if (window[targetPreloadFn]) return window[targetPreloadFn]();
return null;
}]);
Expand Down
1 change: 1 addition & 0 deletions webpack.test.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { existsSync, mkdirSync, writeFileSync, lstatSync } from 'fs';
import { join } from 'path';
import assert from 'assert';
import merge from 'webpack-merge';
import common from './webpack.common.babel';

Expand Down

0 comments on commit 7a51432

Please sign in to comment.