Giter VIP home page Giter VIP logo

tinypubsub's People

Contributors

dhindrik avatar erikrbergman avatar johankson avatar matst80 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinypubsub's Issues

Extend TinyPubSub with generics

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.

Investigate init possibility

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);

Add support for async actions

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.

Memory leak issue?

If using TinyPubSub.Forms and registering event without passing the owner, you will most likely have a memory leak.

Exception handling of Publish with an async callback

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

Add diagnostics tracing

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 an exceptions channel

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?

Pop unsubscribing

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?

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.