@@ -9,15 +9,15 @@ import {Repository} from './repository';
9
9
// tslint:disable:no-any
10
10
11
11
/**
12
- * A mixin class for Application that creates a .repository()
13
- * function to register a repository automatically. Also overrides
14
- * component function to allow it to register repositories automatically.
15
- *
16
- * ```ts
17
- *
18
- * class MyApplication extends RepositoryMixin(Application) {}
19
- * ```
20
- */
12
+ * A mixin class for Application that creates a .repository()
13
+ * function to register a repository automatically. Also overrides
14
+ * component function to allow it to register repositories automatically.
15
+ *
16
+ * ```ts
17
+ *
18
+ * class MyApplication extends RepositoryMixin(Application) {}
19
+ * ```
20
+ */
21
21
export function RepositoryMixin < T extends Class < any > > ( superClass : T ) {
22
22
return class extends superClass {
23
23
// A mixin class has to take in a type any[] argument!
@@ -40,69 +40,69 @@ export function RepositoryMixin<T extends Class<any>>(superClass: T) {
40
40
}
41
41
42
42
/**
43
- * Add a repository to this application.
44
- *
45
- * @param repo The repository to add.
46
- *
47
- * ```ts
48
- *
49
- * class NoteRepo {
50
- * model: any;
51
- *
52
- * constructor() {
53
- * const ds: juggler.DataSource = new DataSourceConstructor({
54
- * name: 'db',
55
- * connector: 'memory',
56
- * });
57
- *
58
- * this.model = ds.createModel(
59
- * 'note',
60
- * {title: 'string', content: 'string'},
61
- * {}
62
- * );
63
- * }
64
- * };
65
- *
66
- * app.repository(NoteRepo);
67
- * ```
68
- */
43
+ * Add a repository to this application.
44
+ *
45
+ * @param repo The repository to add.
46
+ *
47
+ * ```ts
48
+ *
49
+ * class NoteRepo {
50
+ * model: any;
51
+ *
52
+ * constructor() {
53
+ * const ds: juggler.DataSource = new DataSourceConstructor({
54
+ * name: 'db',
55
+ * connector: 'memory',
56
+ * });
57
+ *
58
+ * this.model = ds.createModel(
59
+ * 'note',
60
+ * {title: 'string', content: 'string'},
61
+ * {}
62
+ * );
63
+ * }
64
+ * };
65
+ *
66
+ * app.repository(NoteRepo);
67
+ * ```
68
+ */
69
69
repository ( repo : Class < Repository < any > > ) {
70
70
const repoKey = `repositories.${ repo . name } ` ;
71
71
this . bind ( repoKey ) . toClass ( repo ) ;
72
72
}
73
73
74
74
/**
75
- * Add a component to this application. Also mounts
76
- * all the components repositories.
77
- *
78
- * @param component The component to add.
79
- *
80
- * ```ts
81
- *
82
- * export class ProductComponent {
83
- * controllers = [ProductController];
84
- * repositories = [ProductRepo, UserRepo];
85
- * providers = {
86
- * [AUTHENTICATION_STRATEGY]: AuthStrategy,
87
- * [AUTHORIZATION_ROLE]: Role,
88
- * };
89
- * };
90
- *
91
- * app.component(ProductComponent);
92
- * ```
93
- */
75
+ * Add a component to this application. Also mounts
76
+ * all the components repositories.
77
+ *
78
+ * @param component The component to add.
79
+ *
80
+ * ```ts
81
+ *
82
+ * export class ProductComponent {
83
+ * controllers = [ProductController];
84
+ * repositories = [ProductRepo, UserRepo];
85
+ * providers = {
86
+ * [AUTHENTICATION_STRATEGY]: AuthStrategy,
87
+ * [AUTHORIZATION_ROLE]: Role,
88
+ * };
89
+ * };
90
+ *
91
+ * app.component(ProductComponent);
92
+ * ```
93
+ */
94
94
public component ( component : Class < any > ) {
95
95
super . component ( component ) ;
96
96
this . mountComponentRepository ( component ) ;
97
97
}
98
98
99
99
/**
100
- * Get an instance of a component and mount all it's
101
- * repositories. This function is intended to be used internally
102
- * by component()
103
- *
104
- * @param component The component to mount repositories of
105
- */
100
+ * Get an instance of a component and mount all it's
101
+ * repositories. This function is intended to be used internally
102
+ * by component()
103
+ *
104
+ * @param component The component to mount repositories of
105
+ */
106
106
mountComponentRepository ( component : Class < any > ) {
107
107
const componentKey = `components.${ component . name } ` ;
108
108
const compInstance = this . getSync ( componentKey ) ;
0 commit comments