event_stream 0.1.0

event_stream

Introduction

EventStream makes it easier to expose custom events in Dart.

Getting Started

1\. Add the following to your project's pubspec.yaml and run


dependencies: event_stream:

git: https://github.com/ejsmith/event_stream.git

2\. Add the correct import for your project.

import 'package:eventstream/eventstream.dart';


## Example ##

import 'package:eventstream/eventstream.dart';

import 'dart:async';

class ClassWithEvents implements NotifyPropertyChanged { String someProperty; String someOtherProperty; int _someIntProperty;

final EventStream<PropertyChangedEventArgs> onPropertyChangedEvent = new EventStream<PropertyChangedEventArgs>(); Stream<PropertyChangedEventArgs> get onPropertyChanged => onPropertyChangedEvent.stream;

final EventStream onClosedEvent = new EventStream(); Stream get onClosed => onClosedEvent.stream;

String get someProperty => _someProperty; set someProperty(String value) {

_onPropertyChangedEvent.signal(new PropertyChangedEventArgs('someProperty', value));
_someProperty = value;

}

String get someOtherProperty => _someOtherProperty; set someOtherProperty(String value) {

_onPropertyChangedEvent.signal(new PropertyChangedEventArgs('someOtherProperty', value));
_someOtherProperty = value;

}

int get someIntProperty => _someIntProperty; set someIntProperty(int value) {

_onPropertyChangedEvent.signal(new PropertyChangedEventArgs('someIntProperty', value));
_someIntProperty = value;

}

close() {

_onClosedEvent.signal();

} }

main() { var c = new ClassWithEvents(); c.onPropertyChanged.listen((PropertyChangedEventArgs<String> args) => print('listen1: name=${args.propertyName} value=${args.value} type=${args.value.runtimeType}')); c.onPropertyChanged.listen((PropertyChangedEventArgs<String> args) => print('listen2: name=${args.propertyName} value=${args.value} type=${args.value.runtimeType}')); c.onClosed.listen((_) => print('closed1')); c.onClosed.first.whenComplete(() => print('first closed')); c.someProperty = "test1"; c.someOtherProperty = "test1"; c.someProperty = "test2"; c.someOtherProperty = "test2"; c.someIntProperty = 1; c.close(); c.close(); }


1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  event_stream: ">=0.1.0 <0.2.0"

If your package is an application package you should use any as the version constraint.

2. Install it

You can install packages from the command line:

$ pub get

Alternatively, your editor might support pub. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:event_stream/event_stream.dart';

About

A collection of helper classes to make exposing custom events in Dart easier.

Author

Email eric@codesmithtools.com Eric J. Smith

Homepage

github.com/ejsmith/event_stream

Documentation

www.dartdocs.org/documentation/event_stream/0.1.0/index.html#event_stream

Uploader

eric@codesmithtools.com

Share