dispatch method

  1. @override
Future<Object?> dispatch(
  1. String verb,
  2. List<Object?> args
)
override

Dispatch a verb invocation. Returns any JSON-serialisable value (or a Future thereof) — the bridge JSON-encodes and hands back to the JS Promise. Throw to reject the promise.

args is the list passed by JS (host.fs.read(path) → [path]). Atoms validate arity / types and throw ArgumentError for schema violations so the JS caller gets a clean error message.

Implementation

@override
Future<Object?> dispatch(String verb, List<Object?> args) async {
  Object? arg(int i) => i < args.length ? args[i] : null;
  switch (verb) {
    case 'me':
      return port.me();
    case 'can':
      final right = arg(0);
      if (right is! String || right.isEmpty) {
        throw ArgumentError('member.can requires (right)');
      }
      final opts = arg(1);
      final unit = opts is Map ? opts['unit'] : null;
      return port.can(right, unit: unit is String ? unit : null);
    case 'people':
      return port.people();
    default:
      throw ArgumentError('unknown verb: member.$verb');
  }
}