<commit_before># TinyPubSub
<del>Worlds smallest</del> A really small pub/sub thingy created mostly for Xamarin Forms but should also work else where...

##TLDR

Subscribe

```c#
TinyPubSub.Subscribe("new-duck-added", () => { RebindDuckGui(); });
```
Publish

```c#
TinyPubSub.Publish("new-duck-added");
```

## WHY SHOULD I USE IT?

<img align="right" src="http://i.imgur.com/p0xJYYC.png">

This lib should be used when you want to easily register to events within a small app. It's not meant for data transfer (at least not at this point), it's not thread safe and it's never going to be finished. :)

### EXAMPLE
I have a view that shows ducks. This is my main view. When I edit ducks on another view and the main page is covered I still want the main view to get new ducks before I return to it. I don't want the MainPage to start loading when it gets displayed. 

The main view can listen for the "ducks-added" event and run an action when that happens. When I create a new function in the system I can trust that if I publish an event on the "ducks-added" channel, all my other views subscribing to that event will get notified.

And by following some patterns regarding the NavigationPage(...) we can also make sure that the subscriptions are removed when the view go out of scope.

It's designed with MVVM in mind. Subscription to new events should be done in the ViewModel and the Unsubscription should be made automatically when pages are popped (see usage).

It's not meant to solve world problems so if you want a robust and mature pub/sub framework then there are plenty others out there to use. This is bare metal.

## STATE

Release

## NUGET

https://www.nuget.org/packages/tinypubsub

Added package for profile 259

## USAGE

To subscribe, simply register what "channel" (we call them channels) you would like to subscribe to.

```c#
TinyPubSub.Subscribe("new-duck-added", () => { RebindDuckGui(); });
```

And in another part of you application, publish events to execute the actions that are registered for that channel.

```c#
TinyPubSub.Publish("new-duck-added");
```

### WHAT ABOUT MEMORY ISSUES?
<commit_msg>Updated readme to reflect the Init method changes<commit_after># TinyPubSub
<del>Worlds smallest</del> A really small pub/sub thingy created mostly for Xamarin Forms but should also work else where...

##TLDR

Init - if you are using forms, install the TinyPubSub.Forms package

```csharp
public App ()
{
    // If you are using forms
    TinyPubSubLib.TinyPubSubForms.Init(this);

	// The root page of your application
	var navPage = new NavigationPage(new MainView());

    // If you don't use the TinyPubSubForms.Init(..) method you can register the events yourself like this
	// navPage.Popped += (object sender, NavigationEventArgs e) => TinyPubSub.Unsubscribe(e.Page.BindingContext);
	// navPage.PoppedToRoot += (object sender, NavigationEventArgs e) => TinyPubSub.Unsubscribe(e.Page.BindingContext);
	
	MainPage = navPage;
}

```

Subscribe

```csharp
TinyPubSub.Subscribe("new-duck-added", () => { RebindDuckGui(); });
```
Publish

```csharp
TinyPubSub.Publish("new-duck-added");
```

## WHY SHOULD I USE IT?

<img align="right" src="http://i.imgur.com/p0xJYYC.png">

This lib should be used when you want to easily register to events within a small app. It's not meant for data transfer (at least not at this point), it's not thread safe and it's never going to be finished. :)

### EXAMPLE
I have a view that shows ducks. This is my main view. When I edit ducks on another view and the main page is covered I still want the main view to get new ducks before I return to it. I don't want the MainPage to start loading when it gets displayed. 

The main view can listen for the "ducks-added" event and run an action when that happens. When I create a new function in the system I can trust that if I publish an event on the "ducks-added" channel, all my other views subscribing to that event will get notified.

And by following some patterns regarding the NavigationPage(...) we can also make sure that the subscriptions are removed when the view go out of scope.

It's designed with MVVM in mind. Subscription to new events should be done in the ViewModel and the Unsubscription should be made automatically when pages are popped (see usage).

It's not meant to solve world problems so if you want a robust and mature pub/sub framework then there are plenty others out there to use. This is bare metal.

## STATE

Release

## NUGET

Package are built for profile 259.

###Forms
If you are using TinyPubSub from Xamarin forms, install this package and call the init method as described at the top. You don't have to install any other package.

[https://www.nuget.org/packages/tinypubsub.forms](https://www.nuget.org/packages/tinypubsub.forms)

###Vanilla
[https://www.nuget.org/packages/tinypubsub](https://www.nuget.org/packages/tinypubsub)


## USAGE

To subscribe, simply register what "channel" (we call them channels) you would like to subscribe to.

```c#
TinyPubSub.Subscribe("new-duck-added", () => { RebindDuckGui(); });
```

And in another part of you application, publish events to execute the actions that are registered for that channel.

```c#
TinyPubSub.Publish("new-duck-added");
```

### WHAT ABOUT MEMORY ISSUES?

{'fraction_non_alphanumeric': 0.08915022761760243, 'fraction_numerical': 0.0015174506828528073, 'mean_word_length': 4.225966303270565, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 5, 'lorem ipsum': 0, 'www.': 5, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6996826', 'n_tokens_mistral': 1583, 'n_tokens_neox': 1481, 'n_words': 731}