GithubHelp home page GithubHelp logo

carlosagsmendes / reactive.eventaggregator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shiftkey/reactive.eventaggregator

0.0 2.0 0.0 993 KB

A portable event aggregator for pub-sub messaging, using Rx, for .NET 4+, SL5, WP8+ and Windows Store Apps

License: MIT License

PowerShell 13.37% C# 86.63%

reactive.eventaggregator's Introduction

Reactive.EventAggreator

This is an update of a blog post from José F. Romaniello about using Reactive Extensions to implement an event aggregator. source

Build status

Usage

To install it, just run this from the Package Manager Console:

Install-Package Reactive.EventAggregator

Why bring it back?

Three reasons:

  • I wanted a simple event aggregator, without taking a dependency on an MVVM framework
  • It should be available on NuGet
  • Demonstrate Portable Class Libaries and targetting different platforms from one codebase

Samples

Subscribing to an event

// arrange
var eventWasRaised = false;
var eventPublisher = new EventAggregator();

// act
eventPublisher.GetEvent<SampleEvent>()
              .Subscribe(se => eventWasRaised = true);

eventPublisher.Publish(new SampleEvent());

// assert
eventWasRaised.ShouldBe(true);

Disposing of the event

// arrange
var eventWasRaised = false;
var eventPublisher = new EventAggregator();

// act
var subscription = eventPublisher.GetEvent<SampleEvent>()
                                 .Subscribe(se => eventWasRaised = true);

subscription.Dispose();
eventPublisher.Publish(new SampleEvent());

// assert
eventWasRaised.ShouldBe(false);

Selectively subscribing to an event

// arrange
var eventWasRaised = false;
var eventPublisher = new EventAggregator();

// act
eventPublisher.GetEvent<SampleEvent>()
              .Where(se => se.Status == 1)
              .Subscribe(se => eventWasRaised = true);

eventPublisher.Publish(new SampleEvent { Status = 1 });

// assert
eventWasRaised.ShouldBe(true);

reactive.eventaggregator's People

Contributors

shiftbot avatar shiftkey avatar tamirdresher avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.