event_stream 0.3.2

  • README.md
  • Example
  • Installing
  • Versions
  • 59

event_stream

Introduction

Makes it easier to expose custom events in Dart using the Stream API.

Getting Started

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


dependencies: event_stream: any


2\. Add the correct import for your project.

import 'package:event_stream/event_stream.dart';


## Example ##

import 'package:event_stream/event_stream.dart';

import 'dart:async';

class ClassWithEvents implements NotifyPropertyChanged { String _someProperty;

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) { _someProperty = value; _onPropertyChangedEvent.signal(new PropertyChangedEventArgs('someProperty', value)); }

close() { _onClosedEvent.signal(); } }

main() { var c = new ClassWithEvents(); c.onPropertyChanged.listen((PropertyChangedEventArgs<String> args) => print('changed: name=${args.propertyName} value=${args.value}')); c.onClosed.listen((_) => print('closed')); c.someProperty = "test"; c.close(); }


example/example.dart

import 'package:event_stream/event_stream.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) {
    _someProperty = value;
    _onPropertyChangedEvent.signal(new PropertyChangedEventArgs('someProperty', value));
  }
  
  String get someOtherProperty => _someOtherProperty;
  set someOtherProperty(String value) {
    _someOtherProperty = value;
    _onPropertyChangedEvent.signal(new PropertyChangedEventArgs('someOtherProperty', value));
  }
  
  int get someIntProperty => _someIntProperty;
  set someIntProperty(int value) {
    _someIntProperty = value;
    _onPropertyChangedEvent.signal(new PropertyChangedEventArgs('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.3.2"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages get. 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';
        
Version Uploaded Documentation Archive
0.3.2 Nov 1, 2013 Go to the documentation of event_stream 0.3.2 Download event_stream 0.3.2 archive
0.3.1 Jul 18, 2013 Go to the documentation of event_stream 0.3.1 Download event_stream 0.3.1 archive
0.2.1 Apr 26, 2013 failed Download event_stream 0.2.1 archive
0.1.1 Jan 31, 2013 failed Download event_stream 0.1.1 archive
0.1.0 Jan 31, 2013 failed Download event_stream 0.1.0 archive

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
62 / 100
Health:
Code health derived from static analysis. [more]
94 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0 / 100
Overall score:
Weighted score of the above. [more]
59
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:event_stream/event_stream.dart.

Suggestions

  • Maintain CHANGELOG.md.

    Changelog entries help clients to follow the progress in your code.

  • Use constrained dependencies.

    The pubspec.yaml contains 1 dependency without version constraints. Specify version ranges for the following dependencies: unittest.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Run dartfmt to format lib/event_stream.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
unittest any 0.12.3 0.12.4+1
Transitive dependencies
analyzer 0.25.0+1 0.31.1
args 0.13.7 1.4.2
async 1.13.3 2.0.6
barback 0.15.2+15
charcode 1.1.1
collection 1.14.9
convert 1.1.1 2.0.1
crypto 0.9.2+1 2.0.2+1
glob 1.1.5
http 0.11.3+16
http_multi_server 1.3.2 2.0.4
http_parser 0.0.2+8 3.1.1
matcher 0.12.0+2 0.12.2
mime 0.9.6
package_config 1.0.3
package_resolver 1.0.2
path 1.5.1
pool 1.3.4
pub_semver 1.3.7
shelf 0.6.3 0.7.2
shelf_static 0.2.7
shelf_web_socket 0.0.1+5 0.2.2
source_map_stack_trace 1.1.4
source_maps 0.10.4
source_span 1.4.0
stack_trace 1.9.2
string_scanner 0.1.5 1.0.2
test 0.12.3+9 0.12.35
typed_data 1.1.5
watcher 0.9.7+7
yaml 2.1.13