Total Complexity | 11 |
Complexity/F | 1.38 |
Lines of Code | 51 |
Function Count | 8 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | import {each} from './utils' |
||
2 | |||
3 | 8 | const variables = { |
|
4 | loading() { |
||
5 | 1 | return this.$loadingSyncers |
|
6 | } |
||
7 | } |
||
8 | |||
9 | 8 | const methods = { |
|
10 | refresh(...args) { |
||
11 | 1 | return this.$refreshSyncers(...args) |
|
12 | }, |
||
13 | service(...args) { |
||
14 | 1 | return this.$feathers.service(...args) |
|
15 | } |
||
16 | } |
||
17 | |||
18 | /** |
||
19 | * Create mixin by passed in options |
||
20 | * |
||
21 | * @param {Boolean|Object} options |
||
22 | */ |
||
23 | export default function aliasesMixinMaker(options) { |
||
24 | let isEnabled |
||
25 | 2 | if (typeof options === 'boolean') { |
|
26 | 3 | isEnabled = () => options |
|
27 | } else { |
||
28 | 1 | isEnabled = key => { |
|
29 | 3 | return key in options && options[key] |
|
30 | } |
||
31 | } |
||
32 | |||
33 | 2 | const mixin = { |
|
34 | computed: {}, // Variables |
||
35 | methods: {} |
||
36 | } |
||
37 | |||
38 | 2 | each(variables, (getter, key) => { |
|
39 | 2 | if (isEnabled(key)) { |
|
40 | 1 | mixin.computed[`$${key}`] = getter |
|
41 | } |
||
42 | }) |
||
43 | |||
44 | 2 | each(methods, (caller, key) => { |
|
45 | 4 | if (isEnabled(key)) { |
|
46 | 3 | mixin.methods[`$${key}`] = caller |
|
47 | } |
||
48 | }) |
||
49 | |||
50 | 2 | return mixin |
|
51 | } |
||
52 |