Comment on page
Run time decorate ( + JS support)
Apply decoration in run time
Apply run time decoration is strong advantage of SugoiJS which gives us the flexibility to apply decorators in run-time, either if it because of conditions or lazy-loading.
Applying decorators in run-time provides us the ability to use decorators by pure JS files as well.
For applying decorator method on a call we are able to call the sugoiJS
decorate
methoddecorateProperty(methodToApply, target)
// Using ES6
import {Catch, decorate} from '@sugoi/core';
// Using nodeJS
const {Catch, decorate} = require('@sugoi/core');
class Validator(){
static validate(item){
if(!item.valid){
throw new Error('Invalid')
}
}
}
decorate(Catch(()=>false),Validator);
For applying decorator method on class property we are able to call the sugoiJS
decorateProperty
methoddecorateProperty(methodToApply, target, property)
// Using ES6
import {Catch, decorateProperty} from '@sugoi/core';
// Using nodeJS
const {Catch, decorateProperty} = require('@sugoi/core');
class Validator(){
static validate(item){
if(!item.valid){
throw new Error('Invalid')
}
}
}
decorateProperty(Catch(()=>false), Validator, 'validate');
Last modified 4yr ago