Giter VIP home page Giter VIP logo

pubsub's Introduction

#PubSub PCL

An extremely light-weight, easy to use PCL pub/sub library

###The idea

  • Provide the ability to do de-coupled communitcation without having to include some large (and often opinionated) framework when all you want is pubsub
  • It should be portable so it can be used pretty much wherever
  • Make it stupid simple to use with zero setup

###Get it on Nuget

Install-Package PubSub

nuget dialog image for PubSub PCL ###How to use it First, add a using.

using PubSub;

Listen for stuff you might be interested in.

public class Page
{
	public Page()
	{
		this.Subscribe<Product>( product =>
		{
			// highly interesting things
		});
	}
}

Tell others that interesting things happened.

public class OtherPage
{
	public void ProductPurchased()
	{
		this.Publish( new Product() );
	}
}

Stop listening when you don't care anymore.

public class Page
{
	public void WereDoneHere()
	{
		this.Unsubscribe<Product>();
	}
}

###Some explanation To keep things simple, yet flexible, PubSub PCL is implemented using two core ideas:

  • Different kinds of messages are delineated by CLR type.
    • This avoids the need to have a list of string constants (or just magic strings), enums, whatever to define what you want to listen for/send.
    • This gives us nice strongly-typed data that can be passed from our Publish methods to our Subscribe handlers (i.e. Product above)
  • All interaction with the PubSub system is done through extention methods on System.Object (e.g. Publish, Subscribe and Unsubscribe)
    • This allows for a zero-setup system, you can simply Subscribe on any object and Publish away

###Questions? Thoughts? Feel free to post stuff to the issues page or hit me up on Twitter @brianupta

pubsub's People

Contributors

upta avatar

Watchers

James Cloos avatar Mads Kristensen 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.