feat(mixin): add usage
This commit is contained in:
@@ -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()
|
||||
```
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user