dispatchable 0.0.1-dev.3 copy "dispatchable: ^0.0.1-dev.3" to clipboard
dispatchable: ^0.0.1-dev.3 copied to clipboard

discontinuedreplaced by: class_switch

Package containing the annotations used by the `dispatchable_generator` package to specify which classes to generate dispatchers for.

Build Status

A dart code generator which allows you to work with sub classes in a safer manner.

A class annotated with @Dispatchable() will have two different dispatcher classes generated:

  • _${AnnotatedClassName}Dispatcher<T> which has abstract methods for each sub-class of the annotated class.
    • This class will also have a static method dispatcher
  • _${AnnotatedClassName}DispatcherWithDefaults<T> which has methods for each sub-class of the annotated class returning the abstract method default.

Setup #

Usage #

import 'package:dispatchable/dispatchable.dart';

part 'base.g.dart';

main() {
  // Prints 1.
  print(_$FruitDispatcher.acceptFunc((apple) {
    return 1;
  }, (orange) {
    return 2;
  })(Apple()));
}

@Dispatchable()
abstract class Fruit {}

class Apple extends Fruit {}

class Orange extends Fruit {}

class MyFruitHandler extends _$FruitDispatcher<int> {
  @override
  int apple(Apple apple) {
    return 1;
  }

  @override
  int orange(Orange orange) {
    return 2;
  }
}

0
likes
140
points
15
downloads

Publisher

verified publishernigelgott.com

Weekly Downloads

Package containing the annotations used by the `dispatchable_generator` package to specify which classes to generate dispatchers for.

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on dispatchable