This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Invoice { | |
... | |
doCheckout(shippingDetails){ | |
if(this.validate(shippingDetails)){ | |
this.shippingDetails = shippingDetails | |
var serializedInstance = JSON.stringify(this) | |
$OurAjaxService.post({ | |
url: this.url, | |
data: serializedInstance | |
}).then((response) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Dummy = Class({ | |
someMethod: [ //decoratedMethod | |
"subscribe","$inject", //befores | |
function($$dep1){ | |
//method body | |
}, | |
"trigger: 'action'", //afters (advice with an argument) | |
], | |
anotherMethod: function(){ | |
/* method without advices */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Advices = require("kaop").Advices; | |
Advices.add( | |
function log(){ | |
//meta.args contains the arguments {array} | |
console.log(meta.methodName + " called"); | |
console.log("with arguments: " + meta.args); | |
console.log("returned: " + meta.result); | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Controller = Class({ | |
constructor: function(app){ | |
app.get('/', this.home); | |
app.get('/login', this.login); | |
app.use(this.notFound); | |
}, | |
login: [function(req, res){ | |
//what ever | |
}, "log"], | |
home: [function(req, res){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
import Sidebar from "../Sidebar/Sidebar.main"; | |
import Content from "../Content/Content.main"; | |
import { Advices } from "../../advices/Advices" | |
import { onException, afterMethod } from "kaop-ts" | |
export default class Root extends React.Component<null, null> { | |
@onException(Advices.blameCovfefe) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
import Sidebar from "../Sidebar/Sidebar.main"; | |
import Content from "../Content/Content.main"; | |
import { Advices } from "../../advices/Advices" | |
import { onException, afterMethod } from "kaop-ts" | |
export default class Root extends React.Component<null, null> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AdvicePool, adviceMetadata, IMetadata } from 'kaop-ts' | |
export class Advices extends AdvicePool { | |
static blameCovfefe (@adviceMetadata meta: IMetadata) { | |
meta.exception.message += " despite the constant negative press covfefe" | |
} | |
static throwOnError (@adviceMetadata meta: IMetadata) { | |
if(meta.exception) { | |
throw meta.exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AdvicePool, adviceMetadata, IMetadata } from 'kaop-ts' | |
import { Covfefe } from './covfefe-components' | |
export class Advices extends AdvicePool { | |
static blameRussia (@adviceMetadata meta: IMetadata) { | |
if(meta.exception) { | |
meta.result = <Covfefe/> | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Registry extends AdvicePool { | |
static log (@adviceMetadata meta: IMetadata) { | |
meta.args // Arguments to be received by decorated method | |
meta.propertyKey // Name of the decorated method as string | |
meta.scope // Instance or the context of the call stack | |
meta.rawMethod // Original method (contains metadata) | |
meta.target // Class definition | |
meta.result // The returned value by the method | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { beforeMethod } from 'kaop-ts' | |
import { PersistanceAdvices } from './persistance-advices' | |
import { FlowAdvices } from './flow-advices' | |
import { OrderModel } from './order-model' | |
class View { | |
@beforeMethod(PersistanceAdvices.read, OrderModel) | |
@beforeMethod(FlowAdvices.validate) | |
update (data?) { ... } | |
} |
OlderNewer