feat(mixin): add usage

This commit is contained in:
Julien Fontanet
2022-11-21 11:04:51 +01:00
parent 80969b785f
commit fc4d9accfd
2 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
- mixins can depend on each other, they will be instanciated on-demand
```js
import mixin from '@xen-orchestra/mixin'
class MyMixin {
constructor(app, ...mixinParams) {}
foo() {}
}
class App {
constructor() {
mixin(this, { MyMixin }, [...mixinParams])
}
}
app = new App()
app.myMixin.foo()
```

View File

@@ -12,6 +12,29 @@ Installation of the [npm package](https://npmjs.org/package/@xen-orchestra/mixin
> npm install --save @xen-orchestra/mixin
```
## Usage
- mixins can depend on each other, they will be instanciated on-demand
```js
import mixin from '@xen-orchestra/mixin'
class MyMixin {
constructor(app, ...mixinParams) {}
foo() {}
}
class App {
constructor() {
mixin(this, { MyMixin }, [...mixinParams])
}
}
app = new App()
app.myMixin.foo()
```
## Contributions
Contributions are _very_ welcomed, either on the documentation or on