File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -16,10 +16,14 @@ import styleTransfer from './StyleTransfer/';
16
16
import charRNN from './CharRNN/' ;
17
17
import pix2pix from './Pix2pix/' ;
18
18
import SketchRNN from './SketchRNN' ;
19
+ import preloadRegister from './utils/p5PreloadHelper' ;
19
20
import { version } from '../package.json' ;
20
21
21
- module . exports = {
22
+ const withPreload = {
22
23
imageClassifier,
24
+ } ;
25
+
26
+ module . exports = Object . assign ( { } , preloadRegister ( withPreload ) , {
23
27
KNNClassifier,
24
28
featureExtractor,
25
29
pitchDetection,
@@ -33,4 +37,4 @@ module.exports = {
33
37
...imageUtils ,
34
38
tf,
35
39
version,
36
- } ;
40
+ } ) ;
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2019 ml5
2
+ //
3
+ // This software is released under the MIT License.
4
+ // https://opensource.org/licenses/MIT
5
+
6
+
7
+ /**
8
+ * a list to store all functions to hook p5 preload
9
+ * @param {obj } object or prototype to wrap with
10
+ * @returns obj
11
+ */
12
+ export default function registerPreload ( obj ) {
13
+ if ( typeof window === 'undefined' ) return obj ;
14
+ if ( typeof window . p5 === 'undefined' ) return obj ;
15
+ if ( typeof window . p5 . prototype === 'undefined' ) return obj ;
16
+ if ( typeof window . p5 . prototype . registerPreloadMethod === 'undefined' ) return obj ;
17
+
18
+ const preloadFn = obj ;
19
+ Object . keys ( obj ) . forEach ( ( key ) => {
20
+ const fn = obj [ key ] ;
21
+
22
+ preloadFn [ key ] = function preloads ( ...args ) {
23
+ return fn . apply ( obj , [ ...args , function doingPreloads ( ) {
24
+ const targetPreloadFn = '_decrementPreload' ;
25
+ if ( window [ targetPreloadFn ] ) return window [ targetPreloadFn ] ( ) ;
26
+ return null ;
27
+ } ] ) ;
28
+ } ;
29
+ window . p5 . prototype . registerPreloadMethod ( `${ key } ` , obj ) ;
30
+ } ) ;
31
+
32
+ return obj ;
33
+ }
You can’t perform that action at this time.
0 commit comments