0.1.3 • Published 8 months ago

@barfittc/vue-service-provider v0.1.3

Weekly downloads
-
License
Apache 2.0
Repository
-
Last release
8 months ago

in tsconfig

{
  "compilerOptions": {
    "emitDecoratorMetadata": true
  }
}

or

{
  "references": [{ "path": "node_modules/@barfittc/vue-service-provider/tsconfig.json" }]
}

To use

In your main.

createApp(App)
	.use(addServiceProvider())
	.use(addServiceProviderConsumer())
	.mount('#app')

in your Vue Plugin, register your services

export class TestConsumerTwo {
	hello;
	constructor (hello:string) {
		this.hello = hello;
	}
}
export class TestConsumerOne {

	@service(TestConsumerTwo)
	test!: TestConsumerTwo;

	/** gets called after creation and injection */
	setup() {
		console.log(this.test.hello)
	};
}

export function addServiceProviderConsumer ():Plugin {
	return function(app:App){
		getRegistry(app)
			.AddSingleton(TestConsumerOne) // 1 instance ever created
			.AddTransiant(TestConsumerTwo, "world"); // new instance created every request, you can also pass arguments to the contructor
	}
}

inside your <script setup lang="ts">

const one = getService(TestConsumerOne);
console.log(one.test.hello);
0.1.3

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago