Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

Commit

Permalink
feat: add InjectModel decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
marudor authored and JohannesLamberts committed Sep 5, 2019
1 parent d4a6ee7 commit 0955551
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 30 deletions.
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { InjectModel } from './decorator'
import Component from 'vue-class-component'
import Vue from 'vue'

describe('InjectModel', () => {
@Component
class Test extends Vue {
@InjectModel test: any
}
it('maps correctly', () => {
const component = new Test()
expect(component.$options.injectModels).toStrictEqual(['test'])
})
})
9 changes: 9 additions & 0 deletions src/decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createDecorator } from 'vue-class-component'

// tslint:disable-next-line
export const InjectModel = createDecorator((options: any, key) => {
if (!options.injectModels) {
options.injectModels = []
}
options.injectModels.push(key)
})
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Vue } from 'vue/types/vue'
import Registry from './registry'
import { ModelInstallOptions } from './types'

export * from './decorator'
export { Registry }

interface InstallContext {
Expand Down

0 comments on commit 0955551

Please sign in to comment.