Giter VIP home page Giter VIP logo

k1r0s / kaop-ts Goto Github PK

View Code? Open in Web Editor NEW
262.0 8.0 14.0 2.06 MB

Simple Yet Powerful Library of ES2016 Decorators with Strongly typed method Interceptors like BeforeMethod, AfterMethod, OnException, etc

Home Page: https://k1r0s.github.io/kaop-ts/

License: MIT License

TypeScript 93.62% JavaScript 6.38%
aspect-oriented-programming inversion-of-control decorators typescript metadata single-responsibility-principle

kaop-ts's Introduction

kaop

semantic-release Greenkeeper badge Image travis version Coverage Status dependencies dev-dependencies downloads Known Vulnerabilities

Lightweight, solid, framework agnostic and easy to use library written in TypeScript to deal with Cross Cutting Concerns and improve modularity in your code.

Short Description (or what is an Advice)

This library provides a straightforward manner to implement Advices in your app. Advices are pieces of code that can be plugged in several places within OOP paradigm like 'beforeMethod', 'afterInstance'.. etc. Advices are used to change, extend, modify the behavior of methods and constructors non-invasively.

For in deep information about this technique check the resources.

Demo

https://jsbin.com/bogecojuvi/edit?js,console

Get started

npm install kaop-ts --save

Use a join point to plug it to any method/class:

import { afterMethod } from 'kaop-ts'

const double = afterMethod(meta => meta.result *= 2)

class DummyExample {

  @double
  static calculateSomething (num, num2) {
    return num * num2
  }
}

DummyExample.calculateSomething(3, 3) // 18
DummyExample.calculateSomething(5, 5) // 50

Whats new on 3.0

  • Advices no longer use this to access several utilities.
  • Metadata properties have been renamed. Here you can check the reference .
  • JoinPoints support multiple advices:
// join point decorators expect a list of advices
@beforeMethod(advice1, advice2, advice3)
// even you can provide an advice array using spread operator
@beforeMethod(...adviceList)
someMethod() {

}

Docs

Resources

Credits

Made using TypeScript Library Starter

Similar resources

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.