action_channel 0.0.1 copy "action_channel: ^0.0.1" to clipboard
action_channel: ^0.0.1 copied to clipboard

Communication channel that bundles a sink and a stream, with additional logic. Allows the input/sink type to be different from the output/stream type, simplifying the entry point.

example/main.dart

import 'package:action_channel/action_channel.dart';

final users = <User>{
  User(1, 'John'),
  User(2, 'Tom', muted: true),
  User(3, 'Alex'),
};

void main() {
  final channel = Channel<int, User, String>.controller(
    (id) => users.firstWhere((user) => user.id == id),
    action: (message, user, channel) => user.say(message),
  );

  channel.where((user) => !user.muted).on((user) => 'Hello!');

  channel.once((data) {
    print('First user: ${data.name}');
    return null;
  });

  channel.add(1);
  channel.add(2);
  channel.add(3);
}

/* -= Models =- */

class User {
  final int id;
  final String name;
  final bool muted;

  User(this.id, this.name, {this.muted = false});

  void say(String message) => print('User $id says "$message"');
}
1
likes
160
points
22
downloads

Publisher

verified publisherdrafakiller.com

Weekly Downloads

Communication channel that bundles a sink and a stream, with additional logic. Allows the input/sink type to be different from the output/stream type, simplifying the entry point.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

stream_channel

More

Packages that depend on action_channel