We have created lots decorator in ReactApp.
Now we have to write decorators in every file, My typical Code look something like this.
******** MyComponent.js *************
import {Decorators} from 'decoratorLib';
import React, {Component} from 'react';
const {ModuleLoader, ModuleConfig, log} = Decorators;
@ModuleLoader({
config: {
k1: 'Value 1',
k2: 'Value 2',
viewClass: ModuleViewClass,
...moduleConfig
},
propTypes: {
name: PropTypes.string.isRequired,
age: PropTypes.number,
address: PropTypes.string,
quantity: PropTypes.number
}
})
@ModuleConfig({
config: {
k1: 'Value 1',
k2: 'Value 2',
viewClass: ModuleViewClass,
...moduleConfig
}
})
@log({
config: {
warning: true,
error: true,
breakOnError:false
}
})
class MyComponent extends Component {
}
I am wondering How, we can write these decorators in a sperate file and then write some bridge to pass/connect with classes
Like I can have a decorators.js file, write all decorators here and then write some method or injector to inject these in classes.
Decorators are just values, so you can change your code to
and at that point you're free to move those variables to any file you want, then import them into this file to use them, e.g.
with