A central spot for definitions for notifications concerning various things happening to boxs
| 18 | |
| 19 | /** |
| 20 | * A central spot for definitions for notifications concerning various things happening to boxs |
| 21 | */ |
| 22 | public class Callbacks { |
| 23 | |
| 24 | static public final Dict.Prop<IdempotencyMap<Box.FunctionOfBox>> onDelete = new Dict.Prop<>("onDelete").type() |
| 25 | .toCanon() |
| 26 | .doc("callback that's called when a box is deleted") |
| 27 | .autoConstructs(() -> new IdempotencyMap<>(Box.FunctionOfBox.class)).set(Dict |
| 28 | .readOnly, true); |
| 29 | |
| 30 | |
| 31 | static public final Dict.Prop<IdempotencyMap<Box.FunctionOfBox>> onLoad = new Dict.Prop<>("onLoad").type() |
| 32 | .toCanon() |
| 33 | .doc("callback that's called when a box is loaded") |
| 34 | .autoConstructs(() -> new IdempotencyMap<>(Box.FunctionOfBox.class)).set(Dict |
| 35 | .readOnly, true); |
| 36 | |
| 37 | static public final Dict.Prop<IdempotencyMap<Box.FunctionOfBox>> onSelect = new Dict.Prop<>("onSelect").type() |
| 38 | .toCanon() |
| 39 | .doc("callback that's called when a box is selected") |
| 40 | .autoConstructs(() -> new IdempotencyMap<>(Box.FunctionOfBox.class)).set(Dict |
| 41 | .readOnly, true); |
| 42 | |
| 43 | static public final Dict.Prop<IdempotencyMap<Box.FunctionOfBox>> onDeselect = new Dict.Prop<>("onDeselect").type() |
| 44 | .toCanon() |
| 45 | .doc("callback that's called when a box is deselected") |
| 46 | .autoConstructs(() -> new IdempotencyMap<>(Box.FunctionOfBox.class)).set(Dict |
| 47 | .readOnly, true); |
| 48 | |
| 49 | static public final Dict.Prop<IdempotencyMap<Box.FunctionOfBox>> onExecute = new Dict.Prop<>("onExecute").type() |
| 50 | .toCanon() |
| 51 | .doc("callback that's called when code in a box is executed") |
| 52 | .autoConstructs(() -> new IdempotencyMap<>(Box.FunctionOfBox.class)).set(Dict |
| 53 | .readOnly, true); |
| 54 | |
| 55 | static public final Dict.Prop<IdempotencyMap<Box.BiFunctionOfBoxAnd<String, String>>> onExecuteFragment = new Dict.Prop<>("onExecuteFragment").type() |
| 56 | .toCanon() |
| 57 | .doc("callback that's called when code in a box is executed") |
| 58 | .autoConstructs(() -> new IdempotencyMap<>(Box.BiFunctionOfBoxAnd.class)).set(Dict |
| 59 | .readOnly, true); |
| 60 | |
| 61 | static public final Dict.Prop<IdempotencyMap<Box.FunctionOfBox>> onEdit = new Dict.Prop<>("onEdit").type() |
| 62 | .toCanon() |
| 63 | .doc("callback that's called when code in a box is edited") |
| 64 | .autoConstructs(() -> new IdempotencyMap<>(Box.FunctionOfBox.class)).set(Dict |
| 65 | .readOnly, true); |
| 66 | |
| 67 | |
| 68 | static public void call(Box from, Dict.Prop<IdempotencyMap<Box.FunctionOfBox>> prop) { |
| 69 | Set<String> seen = new LinkedHashSet<>(); |
| 70 | from.breadthFirst(from.upwards()) |
| 71 | .map(x -> x.properties.get(prop)) |
| 72 | .filter(x -> x != null) |
| 73 | .flatMap(x -> x.entrySet() |
| 74 | .stream()) |
| 75 | .forEach(x -> { |
| 76 | if (seen.add(x.getKey())) |
| 77 | x.getValue().apply(from); |
nothing calls this directly
no test coverage detected