GithubHelp home page GithubHelp logo

livingthing.liveblazor's Introduction

LivingThing.LiveBlazor

Update Blazor component in realtime without losing component state, without reloading

Usage

Add namespace

using LivingThing.LiveBlazor;

Initialize it

Blazor.Live()

You are done.

How it works under the hood

When you call Blazor.Live, the current Application domain is scanned for all assemby and types that extends ComponentBase. So If you have a component in a class library, you want to make sure the library is already loaded before calling Blazor.Live. You can force an assemby to load by simply doing

_ = typeof(Namespace.TypeInAssemby).Assemby

We then use Harmony project to patch the found types inserting prefix call into their BuildRenderTree function

This is so we can keep a track of every instance of a type created so far and can therefore automatically call their StateHasChanged when the razor file changes.

TODO: Remove component from the static collection when disposed to avoid memory hog.

We setup a FileWatcher on the project or solution directory so we know when a razor file is changed. When changed, we invoke dotnet to regenerate the .g.cs code for the razor file. The resulting cs file is then compiled against the current types in the application domain. We load the compiled assembly and search for the System.Type of the razor file changed. We also identify the original System.Type that was initially compiled into the application.

We patch the original BuildRenderTree method replacing its IL code with the ILCode of the newly compiled BuildRenderTree method and call StateHasChanged on all component instances of this type.

What is not working yet

Generic Component

A razor file with @bind- that creates an binding Expression causes component excepton ArgumentException: Argument types do not match System.Linq.Expressions.Expression.Constant(object value, Type type)

Client Side Blazor (Web Assembly)

livingthing.liveblazor's People

Contributors

sake402 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.