registerComposer method

void registerComposer(
  1. String function,
  2. FutureOr<Object?> handler(
    1. Object?,
    2. BallCallable
    )
)

Register or override a composition-aware handler for function.

The closure receives the BallCallable so it can call back into the engine to delegate to another module's functions:

std.registerComposer('hypotenuse', (input, engine) {
  final a = (input as Map)['a'] as num;
  final b = (input as Map)['b'] as num;
  final a2 = engine('std', 'math_pow', {'left': a * 1.0, 'right': 2.0});
  final b2 = engine('std', 'math_pow', {'left': b * 1.0, 'right': 2.0});
  return engine('std', 'math_sqrt', {'value': (a2 as num) + (b2 as num)});
});

Implementation

void registerComposer(
  String function,
  FutureOr<Object?> Function(Object?, BallCallable) handler,
) {
  _tombstones.remove(function);
  _dispatch.remove(function);
  _composedDispatch[function] = handler;
}