Giter Club home page Giter Club logo

reflect-extension's Introduction

reflect-extension

Additional methods based on reflect-metadata for runtime reflection and object observe.

This package includes import for reflect-metadata.

npm i reflect-extension

CodeAlter

Attach another method's logic after one method finished.

Reflect.CodeAlter.appendMethod(from: Object, to: Object, fromName: string, toName?: string, injectArgIndex?: number, injectMethodIndex?: number): void

Use injectArgIndex to get result from base method, use injectMethodIndex to get base method.

Class metadata

Easy way to define runtime accessable metadata for class, class members and static class members. All metadatas are defined on constructor of class, can access by given class constructor, class prorotype or class instances.

Reflect.defineClassMetadata(target: any, name?: string): Reflect.IInjectorInformation;
Reflect.getClassMetadata(target: any, name?: string): Reflect.IInjectorInformation | undefined;
Reflect.getClassMetadataList(target: any): Reflect.IInjectorInformation[] | undefined;

Parsing class constructor can only get metadata for static members, while class prototype or instances can only get metadata for instance members.

Class utilities

A set of functions for class data.

Prototype forEach

Function that map object's prorotype from self until meet end condition or reach Object's prototype.

Reflect.forEachPrototype(root: Object, callbackfn: (item: Object) => void, thisArg?: any, endCondition?: (item: Object) => boolean): void;

Find constructor

Function to get constructor from class, class prototype or class instances, not working with plain object.

Reflect.getConstructorOf<T>(target: any): ClassType<T>;

Check inherit

Check if given class is inherit from another class (accept class, class prototype or instances).

Reflect.isClassInherit(source: Object, base: any): boolean;

Is function

Check if given target is function.

Function.isFunction(source: any): source is Function;

Object observer

Create proxy on object, modify or replace behaviours of value get, pre-set and post-set.

Reflect.observeObject<T extends Object>(root: T, options: IObserveOptions): T;

The method use Proxy to insert or replace behavious on value assigning and reading, with support for recursive observe.

reflect-extension's People

Contributors

winup avatar dependabot[bot] avatar

Watchers

 avatar

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.