methodinjector
Injects methods on methods
Alter your methods, functions and callbacks on the fly
Modify arguments, add functionality, inject more on the fly.
Install:
Install with npm
npm install methodinjector
Use standalone
or
Access the library:
Import
;
Require
const methodinjector = ;
Standalone
Basics:
What it does
Inject one or more functions before or after another function.
More or less you have this
{} {}let { ; ;};
into this
{} {}let combined = Injector;
Dynamic add remove
You can add or remove methods on the fly.
{} {}let combined = Injector;// if you want to alter existing one just use it instead as a first parameter// if you use the original one you will loose the current statecombined = Inject;combined = Inject;combined = Inject;
Multiple instances
Every time you inject method with method you can have it merged or separate.
Separate
{} {} {}let combined1 = Injector;let combined2 = Injector;// combined1 !== combined2
Combined
{} {} {}let combined = Injector;combined = Injector;
Add before, add after
You can add one or multiple methods before or after the original one
{} {} {}let combined = Injector;combined = Injector;
Cleanup and restore the original
You can restore the original instance any time you want.
{} {}let combined = Injector;combined = Injector;// combined === original
Play with arguments
Any time you want any of the methods to change the arguments for the next method you can just return array.
{} { args0 = 'a new values'; return args;} { args1 = 'another new value'; return args;}let combined = Injector;combined = Injector;;// and you will have this:// - after 'another' the first parameter will change// - 'anotheranother' will receive the changed argument from before. after 'anotheranother' the second parameter will change.// - 'main' will receive both arguments changed// - this will continue with methods after the main call also