tinystuff / tinypubsub Goto Github PK
View Code? Open in Web Editor NEWWorlds smallest pub/sub thingy created mostly for Xamarin Forms but should also work else where...
License: MIT License
Worlds smallest pub/sub thingy created mostly for Xamarin Forms but should also work else where...
License: MIT License
This is perhaps not a good idea, but worth a discussion.
// Specific type, specific channel (the this parameter is the owner, good for memory management)
TinyPubSub.Subscribe<T>(this, "MyChannel", (T t) => { ... });
// Specific type, any time an event with this type is published no matter what channel
TinyPubSub.Subscribe<T>(this, (T t) => { ... });
The use case is when you want to send types arguments. The channel and type must match in order to subscribe.
Exceptions are caught silently at the moment. This needs to be handled in a nicer way.
Is it possible to create an init function that takes the instance of the app class as an argument and hook up to any required events behind the scene? It would be much nicer to have one init function instead of manually wiring up stuff.
It would perhaps be a second nuget package requiring Xamarin.Forms.Core
Package name: tinypubsub.forms
With a simple method that you throw in at initialization of your forms app.
TinyPubSub.Init(app);
Could we build attribute subscription?
Add an extension method in TinyPubSub.Forms that allows for a construct like the example below.
TinyPubSub.SubscribeForMainThread(Channel.X, () => { RunningOnMainThread(); );
We lack documentation for The generic argument tving we built.
Add support to register the actions to be executed async, for example on a background thread.
For example
TinyPubSub.PublishDelayed("new-duck"); // Should fire later on somehow and not block the GUI and allow the navigation later on to continue.
await Navigation.PopAsync();
Generally I would like to avoid the name PublishDelayedAsync since that method is not async.
If using TinyPubSub.Forms and registering event without passing the owner, you will most likely have a memory leak.
If a call like
TinyPubSub.Subscribe(Channels.AuthenticationRequired, async () => await FunctionThatThrowsAnException());
throws an exception it could crash the entire application since it will be an unhandled exception. We must consider a way to handle this gracefully.
Step 1: Write unit tests to assert that this does indeed crash an application as expected
Step 2: Discuss alternatives on how to solve this
Figure out something smart to get an overview of what's going on. What channels are published to and what data is being transferred.
Add a static exception channel to TinyPubSub where all exceptions are passed to?
TinyPubSub.Subscribe<TinyException>(this, (e) => { ... });
TinyException wraps the inner exception or can be one of the following:
// Non-fatal exception where the listener is null.
ListenerIsNullException : TinyException
// More here?
Any reinitialisation of TinyPubSub should reset all internal state. In the current version (1.2.54) all channels are held intact, causing weird behaviour on UWP if you reinitialise the app in a bad way.
Hi, to start thanks for the framework.
I had an issue with stuff not unsubscribing with Shell.
This happened because the unsubscription automaticly happend only on the navigation page, code:
if (sender is Application && e.PropertyName == "MainPage")
{
var page = (sender as Application).MainPage;
if (page is NavigationPage)
{
BindEvents(page as NavigationPage);
}
}
because of this i needed to update this method to this:
static void App_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (sender is Application && e.PropertyName == "MainPage")
{
var page = (sender as Application).MainPage;
if (page is NavigationPage)
{
BindEvents(page as NavigationPage);
}
else if (page is Shell s)
{
s.Navigating += Shell_Navigating;
}
}
}
private static void Shell_Navigating(object sender, ShellNavigatingEventArgs e)
{
if (e.Source == ShellNavigationSource.Pop
|| e.Source == ShellNavigationSource.Remove)
{
if (sender is Shell s)
{
UnsubscribePage(s.CurrentPage);
}
}
if (e.Source == ShellNavigationSource.PopToRoot)
{
if (sender is Shell s)
{
UnsubscribePage(s.CurrentPage);
}
}
if (e.Source == ShellNavigationSource.Unknown)
{
if(sender is Shell s)
{
if( !(s.CurrentPage is MainView) ) // On initial shell setup this is triggered..
{
UnsubscribePage(s.CurrentPage);
}
}
}
}
I can add this to a PR if you would like to review/merge it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.