NoMe - Notify Method
Have you ever wanted to be notified when some function is invoked? NoMe is at your service.
Once you have function wrapped by NoMe, you can get notified about its invocation like this.
You can call
notify method as many times as you want. These will be executed in order they were added. Arguments passed upon invocation and used context is also preserved.
How to actually create the wrapped function? There are two easy ways.
For most of the time you would probably want to wrap existing function or method.
const wrapped =
Important: Wrapped function is called first and then followed by signed up notification functions.
If you don't want any actual body for a function, NoMe can be used like this:
const wrapped =
Some of your notifiers might require different context (this) than the one used for invocation. You can specify this easily.
It will be remembered and every time when this particular notifier is invoked, the specified context will be used.
Sometimes you might want to remove your handler and stop being notified about further invocations. It can be done like this.
const nomeNotifier = wrapped// sometimes later ...wrapped
Essentially it means you have keep around value returned from
notify call and use that to sign-off the notifier.
Check for wrapper
In case you want easily check if the function is actually wrapped by NoMe (eg. for tests), there is small function returning boolean.
const obj = iAmContext: yesobjsignal =objsignalobjmethod =objmethodobjobjmethod"foo"
After running this, output will be...
I am the signal always executed in window context Method is called and with context of obj I am the notifier and I have foo
NoMe is fully tested. You can check out the result of the tests at Travis CI or clone repository for yourself, run
npm install first and then