Skip to content

Commit 8a8bf3b

Browse files
committed
add some docs
1 parent 458ca6e commit 8a8bf3b

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

docs/src/orchid/resources/wiki/key-concepts.md

+42-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To those new to this project, it might help to go over some keywords:
99
* Call - action taken by hook owner to invoke plugins
1010
* Plugin - something that taps a hook
1111

12-
A **plugin** can **tap** into a **hook** to provide additional functionality
12+
> A **plugin** can **tap** into a **hook** to provide additional functionality
1313
1414
### Hooks
1515

@@ -22,6 +22,47 @@ The hooks library exposes a collection of different types of hooks that support
2222
| **Bail** | Bail hooks allow exiting early with a return value. When any of the tapped function bails, the bail hook will stop executing the remaining ones | `PARALLEL` |
2323
| **Loop** | When a plugin in a loop hook returns a non-undefined value the hook will restart from the first plugin. It will loop until all plugins return undefined. | `PARALLEL` |
2424

25+
### Untapping
26+
27+
Hooks that are tapped return a unique ID that can be used to `untap` from a hook, effectively removing that `tap` from the hook. For convenience, this ID can be specified when tapping the hook to easily override if the callback needs to be updated.
28+
29+
<!--- INCLUDE
30+
import com.intuit.hooks.*
31+
-->
32+
33+
```kotlin
34+
class SimpleHook : SyncHook<(HookContext) -> Unit>() {
35+
fun call() = super.call { f, context -> f(context) }
36+
}
37+
```
38+
39+
<!--- INCLUDE
40+
41+
fun main() {
42+
-->
43+
44+
```kotlin
45+
val simpleHook = SimpleHook()
46+
val tap1 = simpleHook.tap("tap1") {
47+
println("doing something")
48+
}!!
49+
50+
// to remove previously tapped function
51+
simpleHook.untap(tap1)
52+
// or to override previously tapped function
53+
simpleHook.tap("tap1", tap1) {
54+
println("doing something else")
55+
}
56+
```
57+
58+
<!--- INCLUDE
59+
}
60+
-->
61+
62+
<!--- KNIT example-untap-01.kt -->
63+
64+
> With the register interceptors described below, calling `tap` is not guaranteed to actually tap the hook if the interceptor rejects it. In this case, the ID returned from `tap` will be `null`.
65+
2566
### Interceptors
2667

2768
Every hook provides support to register interceptors for different events:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This file was automatically generated from key-concepts.md by Knit tool. Do not edit.
2+
package com.intuit.hooks.example.exampleUntap01
3+
4+
import com.intuit.hooks.*
5+
6+
class SimpleHook : SyncHook<(HookContext) -> Unit>() {
7+
fun call() = super.call { f, context -> f(context) }
8+
}
9+
10+
fun main() {
11+
12+
val simpleHook = SimpleHook()
13+
val tap1 = simpleHook.tap("tap1") {
14+
println("doing something")
15+
}!!
16+
17+
// to remove previously tapped function
18+
simpleHook.untap(tap1)
19+
// or to override previously tapped function
20+
simpleHook.tap("tap1", tap1) {
21+
println("doing something else")
22+
}
23+
}

0 commit comments

Comments
 (0)