ms

method-subscribe

Allows subscribing to any method or function calls using event listeners

Showing:

Popularity

Downloads/wk

32

GitHub Stars

0

Maintenance

Last Commit

5yrs ago

Contributors

1

Package

Dependencies

1

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Method Subscribe

Allows subscribing to method or function calls for any object/instance.

Works by proxying a method (or function) and firing events on every call.

Different from other spy libraries that record interactions with methods this is intended to provide real-time events for method calls.

Useful for testing background logic or firing events from third-party code.

Use

const methodSubscribe = require('method-subscribe');
const proxy = methodSubscribe.proxy(myService, 'doStuff');

proxy.on('call', (e) => {
  console.log('myService.doStuff called', e.arguments);
  // outputs: myService.doStuff called { '0': 123 }
});

myService.doStuff(123);
  • A call event is first emitted with the called arguments
  • The original doStuff method is then called

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial