Skip to content

Latest commit

 

History

History
89 lines (61 loc) · 1.6 KB

examples.md

File metadata and controls

89 lines (61 loc) · 1.6 KB

Logging

sample code:

import { Log } from "./your-log-decorator";
import { beforeMethod } from "kaop-ts";

class ClassName {

  @beforeMethod(Log)
  someMethod() {
    ...
  }
}

Catch decorator

npm package and usage

sample code:

import Catch from "awesome-catch-decorator"

class AnyES6Class {
  @Catch(SyntaxError, () => ({}))
  static parseResponse(unvalidatedInputValue) {
    return JSON.parse(unvalidatedInputValue)
  }
}

// will always return an object
AnyES6Class.parseResponse()
AnyES6Class.parseResponse(",,,s,ds,sd,")
AnyES6Class.parseResponse('{ "message": "Okay, I get it" }')

Http decorator

npm package and usage

package it self is a bit outdated but u get the basic idea:

sample code:

class SomeClass {
  @http({ url: 'localhost/resource'})
  public someMethod (params?: any, error?, result?): void {
    // error should be null if request was success
  }
}

someClassInstance.someMethod()
// $ curl localhost/resource
someClassInstance.someMethod({ id: 1 })
// $ curl localhost/resource?id=1

const prom:Promise<any> = someClassInstance.someMethod()

Scoped-stylesheet decorator

React/Preact npm package

Usage:

Styling Preact Components

sample code:

const style = `
  span { font-size: 20px; color: lightblue; }
`

class ClassName {
  @stylesheet(style)
  render() {
    return <span>something</span>
  }
}