Skip to content

Commit

Permalink
docs: update readme examples
Browse files Browse the repository at this point in the history
  • Loading branch information
k1r0s committed Aug 8, 2017
1 parent ae7b238 commit c136a7a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ DummyExample.calculateSomething(5, 5) // 50

#### How do I define an Advice?

###### as an anonymous function:
###### as an anonymous function ([do not use lambda here!](https://github.com/k1r0s/kaop-ts/issues/18)):
```typescript
@beforeInstance(() => {
@beforeInstance(function() {
// stuff
})
```
###### as an alias:
```typescript
const myCustomAdvice = beforeInstance(() => {
const myCustomAdvice = beforeInstance(function() {
// stuff
})

Expand All @@ -55,7 +55,7 @@ const myCustomAdvice = beforeInstance(() => {
###### as an expression:
```typescript
const myCustomAdvice = (...args) => {
beforeInstance(() => {
return beforeInstance(function() {
// stuff
})
}
Expand All @@ -64,13 +64,13 @@ const myCustomAdvice = (...args) => {
```
###### with generics:
```typescript
const myCustomAdvice = beforeMethod<Type1, 'method'>(() => {
const myCustomAdvice = beforeMethod<Type1, 'method'>(function() {
// stuff
})

@myCustomAdvice // can only used at Type1::method
```
###### (old) as a static property of class that extends `AdvicePool`:
###### (old fashioned) as a static property of class that extends `AdvicePool`:
```typescript
class MyAdvices extends AdvicePool {
static myCustomAdvice(meta) {
Expand All @@ -87,7 +87,7 @@ class MyAdvices extends AdvicePool {
#### Metadata

```typescript
@beforeInstance((meta) => {
@beforeInstance(function(meta) {
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
Expand All @@ -100,7 +100,7 @@ class MyAdvices extends AdvicePool {
#### Advice context `this`

```typescript
@beforeInstance(() => {
@beforeInstance(function() {
this.next()
// triggers the next advice or method in the
// call stack (mandatory if your advice contains async operations)
Expand Down Expand Up @@ -136,7 +136,7 @@ An Advice have access to the original method/instance by [accessing its metadata
```typescript

const log = (path, num) => {
return afterMethod((meta) => {
return afterMethod(function(meta) {
path // "log/file/path"
num // 31
})
Expand Down

0 comments on commit c136a7a

Please sign in to comment.