Skip to content

Commit e0f8686

Browse files
author
Patrick Housley
committed
Added inversify support.
1 parent b37b80b commit e0f8686

18 files changed

+233
-14
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# inversify-vue-test
2-
Test of using InverisfyJS with VueJS and Vuex.
2+
Test of using InverisfyJS with VueJS.

package-lock.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Test of using InverisfyJS with VueJS and Vuex.",
55
"scripts": {
66
"start": "webpack-dev-server --inline --progress",
7-
"build": "webpack --progress --profile --bail --display-optimization-bailout"
7+
"build": "webpack --progress --profile --bail --display-optimization-bailout",
8+
"lint": "tslint --type-check --project tsconfig.json 'src/**/*.ts'"
89
},
910
"engines": {
1011
"node": ">=8"
@@ -21,8 +22,10 @@
2122
"homepage": "https://github.com/patrickhousley/inversify-vue-test#readme",
2223
"dependencies": {
2324
"inversify": "4.1.1",
25+
"reflect-metadata": "0.1.10",
2426
"vue": "2.3.4",
2527
"vue-class-component": "5.0.1",
28+
"vue-property-decorator": "5.1.0",
2629
"vuex": "2.3.1"
2730
},
2831
"devDependencies": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>
2+
<div>Application Name: {{name}}</div>
3+
<div>Application Version: {{version}}</div>
4+
</div>

src/app/additional-info/additional-info.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Component, Vue } from 'vue-property-decorator';
2+
import { injectable } from 'inversify';
3+
import * as Template from './additional-info.component.html?style=./additional-info.component.scss';
4+
5+
@Template
6+
@Component
7+
@injectable()
8+
export class AdditionalInfoComponent extends Vue {
9+
public name = 'Inversify Vue Test';
10+
public version = '0.0.1';
11+
12+
constructor() {
13+
super();
14+
console.log('Constructing additional info');
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<div>
22
<h1>Vue Test</h1>
33
<h3>{{ message }}</h3>
4+
<additional-info></additional-info>
45
</div>
File renamed without changes.

src/app/app.component.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, Vue } from 'vue-property-decorator';
2+
import { injectable } from 'inversify';
3+
import { appContainer, containerTypes, componentResolver, VueClass } from 'src/app/app.container';
4+
import * as Template from './app.component.html?style=./app.component.scss';
5+
6+
@Template
7+
@Component({
8+
components: {
9+
'additional-info': componentResolver(() => appContainer.get<VueClass>(containerTypes.AdditionalInfoComponent))
10+
}
11+
})
12+
@injectable()
13+
export class AppComponent extends Vue {
14+
public message = 'Hello Vue.js!';
15+
}

src/app/app.container.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Container } from 'inversify';
2+
3+
import { containerTypes } from 'src/app/app.types';
4+
import { VueClass } from 'src/lib/component-resolver';
5+
import { GoodbyAppComponent } from 'src/app/goodby-app.component';
6+
import { AdditionalInfoComponent } from 'src/app/additional-info/additional-info.component';
7+
8+
const appContainer = new Container();
9+
10+
// Components need to be bound as a constructor
11+
appContainer.bind<VueClass>(containerTypes.AppComponent).toConstructor(GoodbyAppComponent);
12+
appContainer.bind<VueClass>(containerTypes.AdditionalInfoComponent).toConstructor(AdditionalInfoComponent);
13+
14+
export { appContainer };
15+
export { containerTypes } from 'src/app/app.types';
16+
export { componentResolver, VueClass } from 'src/lib/component-resolver';

src/app/app.types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const containerTypes = {
2+
AppComponent: Symbol('AppComponent'),
3+
AdditionalInfoComponent: Symbol('AdditionalInfoComponent')
4+
};

src/app/goodby-app.component.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, Vue } from 'vue-property-decorator';
2+
import { injectable } from 'inversify';
3+
import { appContainer, containerTypes, componentResolver, VueClass } from 'src/app/app.container';
4+
import * as Template from './app.component.html?style=./app.component.scss';
5+
6+
@Template
7+
@Component({
8+
components: {
9+
'additional-info': componentResolver(() => appContainer.get<VueClass>(containerTypes.AdditionalInfoComponent))
10+
}
11+
})
12+
@injectable()
13+
export class GoodbyAppComponent extends Vue {
14+
public message = 'Goodby Vue.js!';
15+
}

src/components/app/app.component.ts

-9
This file was deleted.

src/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<meta http-equiv="x-ua-compatible" content="ie=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
77
<title>inversify-vue-test</title>
8+
9+
<script src="https://cdnjs.cloudflare.com/ajax/libs/reflect-metadata/0.1.10/Reflect.js"></script>
810
</head>
911

1012
<body>

src/lib/component-resolver.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { VueClass } from 'vue-class-component/lib/declarations';
2+
export { VueClass } from 'vue-class-component/lib/declarations';
3+
4+
export function componentResolver<V extends VueClass>(componentConstructor: () => V) {
5+
return (resolve: (component: V) => void, reject: (error: Error) => void) => {
6+
try {
7+
resolve(componentConstructor());
8+
} catch (error) {
9+
reject(error as Error);
10+
}
11+
};
12+
}

src/main.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import Vue from 'vue';
2-
import { AppComponent } from 'src/components/app/app.component';
2+
import { containerTypes } from 'src/app/app.types';
3+
import { appContainer } from 'src/app/app.container';
34

5+
/* tslint:disable:no-unused-expression */
46
new Vue({
57
el: '#app-main',
6-
render: r => r(AppComponent)
7-
});
8+
render: r => r(appContainer.get(containerTypes.AppComponent))
9+
});

store.zip

1.63 KB
Binary file not shown.

tslint.json

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{
2+
"extends": "tslint:recommended",
3+
"rulesDirectory": [],
4+
"defaultSeverity": "error",
5+
"rules": {
6+
"align": {
7+
"options": [
8+
"parameters",
9+
"statements",
10+
"arguments",
11+
"elements"
12+
]
13+
},
14+
"arrow-parens": {
15+
"options": ["ban-single-arg-parens"]
16+
},
17+
"comment-format": false,
18+
"curly": {
19+
"options": ["ignore-same-line"]
20+
},
21+
"indent": {
22+
"options": ["spaces", 2]
23+
},
24+
"interface-name": {
25+
"options": ["never-prefix"]
26+
},
27+
"jsdoc-format": false,
28+
"max-line-length": false,
29+
"member-ordering": {
30+
"options": {
31+
"order": [
32+
"private-static-field",
33+
"protected-static-field",
34+
"public-static-field",
35+
"public-static-method",
36+
"protected-static-method",
37+
"private-static-method",
38+
"private-instance-field",
39+
"protected-instance-field",
40+
"public-instance-field",
41+
"public-constructor",
42+
"protected-constructor",
43+
"private-constructor",
44+
"public-instance-method",
45+
"protected-instance-method",
46+
"private-instance-method"
47+
]
48+
}
49+
},
50+
"no-any": true,
51+
"no-console": false,
52+
"no-duplicate-variable": true,
53+
"no-inferrable-types": false,
54+
"no-invalid-this": true,
55+
"no-switch-case-fall-through": true,
56+
"object-literal-sort-keys": false,
57+
"quotemark": {
58+
"options": [
59+
"single",
60+
"jsx-double"
61+
]
62+
},
63+
"trailing-comma": {
64+
"options":[
65+
{
66+
"multiline": "never",
67+
"singleline": "never"
68+
}
69+
]
70+
},
71+
"variable-name": {
72+
"options": [
73+
"ban-keywords",
74+
"check-format",
75+
"allow-pascal-case",
76+
"allow-leading-underscore"
77+
]
78+
},
79+
80+
"array-type": {
81+
"options": ["array"]
82+
},
83+
"await-promise": true,
84+
"deprecation": {
85+
"severity": "warn"
86+
},
87+
"binary-expression-operand-order": true,
88+
"import-blacklist": {
89+
"options": ["rxjs"]
90+
},
91+
"linebreak-style": {
92+
"options": ["LF"]
93+
},
94+
"no-boolean-literal-compare": true,
95+
"no-default-export": true,
96+
"no-floating-promises": true,
97+
"no-for-in-array": true,
98+
"no-import-side-effect": true,
99+
"no-inferred-empty-object-type": true,
100+
"no-invalid-template-strings": true,
101+
"no-irregular-whitespace": true,
102+
"no-magic-numbers": {
103+
"severity": "warn"
104+
},
105+
"no-require-imports": true,
106+
"no-non-null-assertion": true,
107+
"no-null-keyword": false,
108+
"no-object-literal-type-assertion": true,
109+
"no-unnecessary-type-assertion": true,
110+
"no-sparse-arrays": true,
111+
"no-unbound-method": {
112+
"options": ["ignore-static"]
113+
},
114+
"no-unnecessary-callback-wrapper": true,
115+
"no-unsafe-any": true,
116+
"no-void-expression": true,
117+
"ordered-imports": false,
118+
"prefer-conditional-expression": true,
119+
"prefer-method-signature": true,
120+
"prefer-object-spread": true,
121+
"prefer-switch": true,
122+
"prefer-template": true,
123+
"promise-function-async": true,
124+
"restrict-plus-operands": true,
125+
"type-literal-delimiter": true,
126+
"use-default-type-parameter": true
127+
}
128+
}

0 commit comments

Comments
 (0)