Last active
August 29, 2018 08:14
-
-
Save ffMathy/816c0b905f27c737e4533927ebd3f873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Container, Inject, Injectable } from '@fluffy-spoon/inverse'; | |
import { VueInverse, VueInjectable } from '@fluffy-spoon/inverse-vue'; | |
import Component from 'vue-class-component'; | |
import Vue from 'vue'; | |
//we first create our IOC container. | |
var container = new Container(); | |
//we provide that to the VueInverse plugin. | |
Vue.use(VueInverse, container); | |
@Injectable /* the Injectable decorator makes it possible for this class to be injected automatically */ | |
class Foo { } | |
@Component({ | |
template: '<div></div>' | |
}) | |
@VueInjectable /* the VueInjectable decorator makes it possible for this Vue component to have its dependencies injected via the constructor when passed to Vue.js */ | |
class MyVueComponent extends Vue { | |
constructor( | |
@Inject private foo: Foo) /* the Inject decorator is needed to have the dependency be injected automatically */ | |
{ | |
super(); | |
console.log('foo is injected - look:', foo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment