Gathering detailed insights and metrics for @vue-ioc/core
Gathering detailed insights and metrics for @vue-ioc/core
Gathering detailed insights and metrics for @vue-ioc/core
Gathering detailed insights and metrics for @vue-ioc/core
npm install @vue-ioc/core
Typescript
Module System
Node Version
NPM Version
53.3
Supply Chain
95.1
Quality
75.6
Maintenance
50
Vulnerability
99.6
License
TypeScript (78.4%)
Vue (15.06%)
JavaScript (5.79%)
HTML (0.75%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
5,742
Last Day
2
Last Week
9
Last Month
31
Last Year
321
44 Stars
64 Commits
2 Forks
2 Watchers
45 Branches
2 Contributors
Updated on Dec 10, 2024
Minified
Minified + Gzipped
Latest Version
0.2.3
Package Id
@vue-ioc/core@0.2.3
Unpacked Size
65.69 kB
Size
17.52 kB
File Count
23
NPM Version
lerna/3.18.4/node@v12.16.1+x64 (win32)
Node Version
12.16.1
Cumulative downloads
Total Downloads
Last Day
100%
2
Compared to previous day
Last Week
28.6%
9
Compared to previous week
Last Month
-39.2%
31
Compared to previous month
Last Year
-53.5%
321
Compared to previous year
IoC and DI for Vue powered by InversifyJS and inspired by Angular @Module syntactic sugar.
experimentalDecorators: true
and emitDecoratorMetadata: true
@Module
by providers
(using InversifyJS under the hood). The hierarchy is bound to Vue components tree.@Effects
from ngrx
).@PostConstruct
and @BeforeDestroy
- decorators for methods called when instance is created or destroyed by container.@OnEvent('submitForm')
@Module
can be bound only to Vue component.@Inject()
for Vue component constructor arguments (because you can't define own constructor
using vue-class-component
). Only Vue component class fields are supported.vue-ioc
uses following peerDependencies
:
inversify
reflect-metadata
vue-class-component
vue
1 2# NPM 3npm install @vue-ioc/core inversify reflect-metadata vue-class-component vue --save 4 5# Yarn 6yarn add @vue-ioc/core inversify reflect-metadata vue-class-component vue
You must explicitly install vue-ioc
via Vue.use()
in your app main entrypoint:
1// main.ts 2import Vue from 'vue' 3import {VueIocPlugin} from '@vue-ioc/core' 4 5Vue.use(VueIocPlugin)
Create simple injectable service HttpService
:
1// ./services/HttpService.ts 2import {Injectable} from '@vue-ioc/core'; 3 4@Injectable() 5export class HttpService { 6 public get(url: string): Promise<any> { 7 return fetch(url).then(rs => rs.json()); 8 } 9}
Add root container using @Module
decorator at your top level App component and setup providers:
1// App.vue 2<template> 3 <div> 4 <HelloWorld/> 5 </div> 6</template> 7<script lang="ts"> 8 import Vue from 'vue' 9 import Component from 'vue-class-component' 10 import {Module} from '@vue-ioc/core'; 11 import {HttpService} from './services/HttpService'; 12 import HelloWorld from './components/HelloWorld.vue'; 13 14 @Module({ 15 providers: [ 16 HttpService 17 ] 18 }) 19 @Component({ 20 components: { HelloWorld } 21 }) 22 export default class App extends Vue { 23 } 24</script>
Inject HttpService
to <HelloWorld>
component:
1// ./components/HelloWorld.vue 2<template> 3 <div> 4 <h2 v-if="user">Hello {{user.firstName}} {{user.lastName}}!</h2> 5 </div> 6</template> 7<script lang="ts"> 8 import Vue from 'vue' 9 import Component from 'vue-class-component' 10 import {Inject} from '@vue-ioc/core'; 11 import {HttpService} from '../services/HttpService'; 12 13 @Component() 14 export default class HelloWorld extends Vue { 15 16 @Inject() 17 public httpService: HttpService; 18 19 public user = null; 20 21 public async created() { 22 this.user = await this.httpService.get('./hello.json'); 23 } 24 } 25</script>
1@Module({ 2 providers: [ 3 // useClass 4 { provide: HttpService, useClass: HttpService }, 5 6 // useClass shortcut 7 HttpService, 8 9 // useValue 10 { provide: HttpService, useValue: httpService }, 11 12 // useFactory 13 { provide: HttpService, useFactory: (injector) => /* ...injector.get(FooService)... */ } 14 ] 15})
Default value: 'self'
Available values: 'root', 'self'
@Injectable( { providedIn: 'root' } )
will bind service in root (App) container always as singleton.
You may also override this setting at @Module
providers level in both directions:
1@Module({ 2 providers: [ 3 { provide: HttpService, useClass: HttpService, providedIn: 'root' }, // overrides @Injectable() 4 { provide: OtherService, useClass: OtherService, providedIn: 'self' }, // overrides @Injectable( {providedIn: 'root'} ) 5 ] 6})
@PostConstruct()
and @BeforeDestroy()
are two built in instance listeners. You may create custom instance handlers
like @OnEvent('submitForm')
by creating a decorator using createInstanceHandlerDecorator
1// bus/EventBus.ts 2import Vue from 'vue'; 3import {Injectable} from '@vue-ioc/core'; 4 5@Injectable() 6export class EventBus { 7 8 private bus: Vue = new Vue(); 9 10 dispatch(name: string, data: any) { 11 this.bus.$emit(name, data); 12 } 13 14 addListener(name: string, listener: (data: any) => void) { 15 this.bus.$on(name, listener) 16 } 17 18 removeListener(name: string, listener: (data: any) => void) { 19 this.bus.$off(name, listener) 20 } 21} 22
@OnEvent(name:string)
decorator1// bus/OnEvent.ts 2import {createInstanceHandlerDecorator} from '@vue-ioc/core'; 3import {EventBus} from './EventBus'; 4 5export function OnEvent(name: string) { 6 return createInstanceHandlerDecorator(({injector, instance, method}) => { 7 // attach handler - a place where listeners should be attached 8 const bus: EventBus = injector.get(EventBus); // you have access to injector where all services can be retrieved 9 const boundMethod = instance[method].bind(instance); // bound method to `this` of instance 10 bus.addListener(name, boundMethod); 11 return () => { 12 // detach handler - a place where all listeners should be detached 13 bus.removeListener(name, boundMethod); 14 }; 15 }); 16}
1// view/Form.vue 2<template> 3 <div> 4 <button @click="submitForm">Submit</button> 5 </div> 6</template> 7<script lang="ts"> 8 import Vue from 'vue' 9 import Component from 'vue-class-component' 10 import {Inject} from '@vue-ioc/core'; 11 import {EventBus} from '../bus/EventBus'; 12 13 @Component() 14 export default class SomeForm extends Vue { 15 16 @Inject() 17 public bus!: EventBus; 18 19 public submitForm() { 20 this.bus.dispatch('submitForm', { firstName: 'John', lastName: 'Doe'}) 21 } 22 } 23</script>
1// actions/SubmitForm.ts 2import {OnEvent} from '../bus/OnEvent' 3import {Injectable} from '@vue-ioc/core'; 4 5@Injectable() 6export class SubmitForm { 7 8 @OnEvent('submitForm') 9 perform (data) { 10 // do something with data 11 } 12}
vue-ioc uses following default options for creating Inversify containers:
{
autoBindInjectable: false,
defaultScope: 'Singleton',
skipBaseClassChecks: true,
}
To override or add other options, please use containerOptions
of plugin options:
1Vue.use(VueIocPlugin, { 2 containerOptions: { 3 // options of Inversify container: 4 // https://github.com/inversify/InversifyJS/blob/master/wiki/container_api.md#container-options 5 } 6})
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
Found 1/20 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
138 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-03-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More