Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Daddoon/Daddoon.Blazor

Repository files navigation

Daddoon.Blazor

Extensions for the Blazor project

Installation

In your Program.cs file, when instanciating your BrowserRenderer class, you should add the DaddoonBlazorExtensionScripts component to your DOM.

public static void Main(string[] args)
{
    var serviceProvider = new BrowserServiceProvider(configure =>
    {
        /* Instanciate your services */
    });

    br = new BrowserRenderer(serviceProvider);
    br.AddComponent<DaddoonBlazorExtensionScripts>("daddoon");
    br.AddComponent<App>("app");
}

Assuming you have a "daddoon" tag in the body of your index.html file. You can replace by anything else.

HOW TO

Mainly adding some currently missing interop to the browser, some helpers and else !

Platform: Rendering Engine

Browser.Platform.RenderingEngine

Returning values like:

Unknown = 0,
WebKit = 1,
Blink = 2,
Gecko = 3,
MSIE = 4,
MSEdge = 5

Platform: Browser Family

Not very exhaustive at the moment, you can call it like:

Browser.Platform.BrowserFamily

Returning values like:

Other = 0,
InternetExplorer = 1,
InternetExplorer11 = 2,
Edge = 3

Platform: UserAgent, Name, Version

Browser.Platform.UserAgent;
Browser.Platform.Name;
Browser.Platform.Version;

SetTimeout

Browser.SetTimeout(delegate () { /* do something */ }, 1000);
Browser.SetTimeout(async delegate () { /* do something else */ }, 1000);

Some overloads are available but are mainly unecessary

Cookies

Based on js.cookie.js, with the corresponding overloads, you can stock string or object (as serialized data)

Set:

Browser.Cookies.Set("myCookie", "myValue");
Browser.Cookies.Set<T>("myCookie", myObject); //Showing the generic type here is just for readability

Get:

Browser.Cookies.Get("myCookie");

Remove:

Browser.Cookies.Remove("myCookie");

Local Storage

Set:

Browser.LocalStorage.Set("myStorage", "myValue");
Browser.LocalStorage.Set<T>("myStorage", myValue);

Get:

Browser.LocalStorage.Get("myStorage");
Browser.LocalStorage.Get<T>("myStorage");

Remove:

Browser.LocalStorage.Remove("myStorage");

Clear:

Browser.LocalStorage.Clear();

Session Storage

Likewise Local Storage:

Set:

Browser.SessionStorage.Set("myStorage", "myValue");
Browser.SessionStorage.Set<T>("myStorage", myValue);

Get:

Browser.SessionStorage.Get("myStorage");
Browser.SessionStorage.Get<T>("myStorage");

Remove:

Browser.SessionStorage.Remove("myStorage");

Clear:

Browser.SessionStorage.Clear();

Location

Clear:

Browser.Location.Reload();

NOTE

There is more in this package, with IHttpClient and IHttpClientSafe implementation, but i will write for this later.