1
1
import op from 'object-path' ;
2
+ import _ from 'underscore' ;
2
3
import Reactium , { isBrowserWindow } from 'reactium-core/sdk' ;
3
4
import manifestLoader from 'manifest' ;
4
5
5
6
class ReactiumDependencies {
6
7
constructor ( ) {
7
8
this . loaded = false ;
8
9
this . loadedModules = { } ;
9
- this . actions = { } ;
10
- this . actionTypes = {
11
- DOMAIN_UPDATE : 'DOMAIN_UPDATE' ,
12
- } ;
13
10
this . services = { } ;
14
- this . reducers = { } ;
15
11
this . plugins = { } ;
16
12
this . plugableConfig = { } ;
17
13
18
14
// Just used to determine if is a custom type
19
- this . coreTypes = [
20
- 'allActionTypes' ,
21
- 'allActions' ,
22
- 'allReducers' ,
23
- 'allInitialStates' ,
24
- 'allServices' ,
25
- 'allMiddleware' ,
26
- 'allEnhancers' ,
27
- 'allPlugins' ,
28
- 'allHooks' ,
29
- ] ;
15
+ this . coreTypes = [ 'allServices' , 'allPlugins' , 'allHooks' ] ;
30
16
31
17
// Things to be mapped on deps now
32
18
this . coreTypeMap = {
33
- allActionTypes : 'actionTypes' ,
34
- allActions : 'actions' ,
35
19
allServices : 'services' ,
36
20
allPlugins : 'plugins' ,
37
21
} ;
@@ -56,29 +40,48 @@ class ReactiumDependencies {
56
40
}
57
41
58
42
async loadAll ( type ) {
59
- return Promise . all (
60
- op . get ( this . manifest , [ type ] , [ ] ) . map ( dep => {
61
- const { name, domain, loader } = dep ;
62
- if ( op . has ( this , [ 'loadedModules' , name , domain ] ) ) {
63
- const loadedModule = op . get ( this , [
64
- 'loadedModules' ,
65
- name ,
66
- domain ,
67
- ] ) ;
68
- return Promise . resolve ( loadedModule ) ;
69
- } else {
70
- return dep . loader ( ) . then ( loadedModule => {
71
- const { name, domain, module } = loadedModule ;
72
-
73
- op . set (
74
- this ,
75
- [ 'loadedModules' , name , domain ] ,
76
- loadedModule ,
43
+ return _ . compact (
44
+ await Promise . all (
45
+ op . get ( this . manifest , [ type ] , [ ] ) . map ( async dep => {
46
+ try {
47
+ const { name, domain, loader } = dep ;
48
+ const { load = true } = await Reactium . Hook . run (
49
+ 'load-dependency' ,
50
+ { name, domain, module } ,
51
+ Reactium . Enums . priority . highest ,
52
+ 'REACTIUM-DEP-MODULE-LOAD' ,
77
53
) ;
78
- return loadedModule ;
79
- } ) ;
80
- }
81
- } ) ,
54
+
55
+ if ( load ) {
56
+ if ( op . has ( this , [ 'loadedModules' , name , domain ] ) ) {
57
+ const loadedModule = op . get ( this , [
58
+ 'loadedModules' ,
59
+ name ,
60
+ domain ,
61
+ ] ) ;
62
+
63
+ return loadedModule ;
64
+ } else {
65
+ const loadedModule = await loader ( ) ;
66
+ const { name, domain } = loadedModule ;
67
+
68
+ op . set (
69
+ this ,
70
+ [ 'loadedModules' , name , domain ] ,
71
+ loadedModule ,
72
+ ) ;
73
+
74
+ return loadedModule ;
75
+ }
76
+ }
77
+ } catch ( error ) {
78
+ console . error ( 'loadAll error' , error ) ;
79
+ return Promise . resolve ( undefined ) ;
80
+ }
81
+
82
+ return ;
83
+ } ) ,
84
+ ) ,
82
85
) ;
83
86
}
84
87
0 commit comments