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

discontinuedreplaced by: class_switch
outdated

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.fruitDispatcher((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
0
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.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on dispatchable