Updated Creating Plugins (markdown)

Zack 2018-10-14 19:50:09 -04:00
parent d63d9e5450
commit b161dd3063
1 changed files with 9 additions and 7 deletions

@ -248,11 +248,11 @@ This function monkey-patches a method on an object. The patching callback may be
|`[options.once=false]`|boolean|Set to `true` if you want to automatically unpatch method after first call.|
|`[options.silent=false]`|boolean|Set to `true` if you want to suppress log messages about patching and unpatching. Useful to avoid clogging the console in case of frequent conditional patching/unpatching, for example from another monkeyPatch callback.|
|`[options.displayName]`|string|You can provide meaningful name for class/object provided in `what` param for logging purposes. By default, this function will try to determine name automatically.|
|`options.before`|PatchFunction|Callback that will be called before original target method call. You can modify arguments here, so it will be passed to original method. Can be combined with `after`.|
|`options.after`|PatchFunction|Callback that will be called after original target method call. You can modify return value here, so it will be passed to external code which calls target method. Can be combined with `before`.|
|`options.instead`|PatchFunction|Callback that will be called instead of original target method call. You can get access to original method using `originalMethod` parameter if you want to call it, but you do not have to. Can't be combined with `before` and `after`.|
|`options.before`|[PatchFunction](#callback-patchfunction)|Callback that will be called before original target method call. You can modify arguments here, so it will be passed to original method. Can be combined with `after`.|
|`options.after`|[PatchFunction](#callback-patchfunction)|Callback that will be called after original target method call. You can modify return value here, so it will be passed to external code which calls target method. Can be combined with `before`.|
|`options.instead`|[PatchFunction](#callback-patchfunction)|Callback that will be called instead of original target method call. You can get access to original method using `originalMethod` parameter if you want to call it, but you do not have to. Can't be combined with `before` and `after`.|
**@Returns** `{CancelPatch}` - A cancel function which allows you to undo the patch.
**@Returns** [`{CancelPatch}`](#callback-patchfunction) - A cancel function which allows you to undo the patch.
***
@ -331,21 +331,23 @@ Function with no arguments and no return value that may be called to revert chan
#### Callback: PatchFunction
A callback that modifies method logic. This callback is called on each call of the original method and is provided all data about original call. Any of the data can be modified if necessary, but do so wisely.
|Parameter|Type|Description|
|-|-|:-|
|`PatchData`|object|Data object with information about current call and original method that you may need in your patching callback.|
|`data`|[PatchData](#interface-patchdata)|Data object with information about current call and original method that you may need in your patching callback.|
**@Returns** {*} Makes sense only when used as `instead` parameter in {@link monkeyPatch}. If something other than `undefined` is returned, the returned value replaces the value of `data.returnValue`. If used as `before` or `after` parameters, return value is ignored.
**@Returns** {*} Makes sense only when used as `instead` parameter in [`monkeyPatch`](#monkeypatchmodule-methodname-options). If something other than `undefined` is returned, the returned value replaces the value of `data.returnValue`. If used as `before` or `after` parameters, return value is ignored.
***
#### Interface: PatchData
A callback that modifies method logic. This callback is called on each call of the original method and is provided all data about original call. Any of the data can be modified if necessary, but do so wisely.
|Property|Type|Description|
|-|-|:-|
|`thisObject`|object|Original `this` value in current call of patched method.|
|`methodArguments`|Arguments|Original `arguments` object in current call of patched method. Please, never change function signatures, as it may cause a lot of problems in future.|
|`CancelPatch`|CancelPatch|Function with no arguments and no return value that may be called to reverse patching of current method. Calling this function prevents running of this callback on further original method calls.|
|`CancelPatch`|[CancelPatch](#callback-cancelpatch)|Function with no arguments and no return value that may be called to reverse patching of current method. Calling this function prevents running of this callback on further original method calls.|
|`originalMethod`|function|Reference to the original method that is patched. You can use it if you need some special usage. You should explicitly provide a value for `this` and any method arguments when you call this function.|
|`callOriginalMethod`|function|This is a shortcut for calling original method using `this` and `arguments` from original call.|
|`returnValue`|*|This is a value returned from original function call. This property is available only in `after` callback or in `instead` callback after calling `callOriginalMethod` function.|