Giter VIP home page Giter VIP logo

blazorrealm's Introduction

Blazor Realm

Redux state management for Blazor. Realm takes the design patterns of Redux, centralized state and single direction data flow, and brings them to Blazor.

Centralized state.

Application state is defined in one location. This helps reason about an application's data needs and acts as a single source of truth, eliminating state conflicts.

Single direction data flow.

Instead of updating the application state directly, the UI dispatches actions for the Realm store to handle. The store, in turn, updates the centralized state and triggers a rerender of the UI.

View as a function of data.

The single direction data flow pattern works well with UI frameworks that render UI, or views, as a function of data. The component UI model of Blazor works in this way. Components receive data as props and render based on the provided values. Components rerender as data/props change, receiving the updated values for rendering.

blazorrealm's People

Contributors

dworthen avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

nijoseph

blazorrealm's Issues

All Async components refresh not only the one being updated

Hi, I have 3 trees of data that I get from 3 api endpoints and a paged list of data based on criteria selected in the trees. The trees also need to load their branches on demand. When you make a selection criteria in one tree it needs to update the other 2 and reload the paged list.

When I page all 4 components reload, to try to resolve this I split the store to test

services.AddRealmStore(new State1(), Reducers.1RootReducer);
services.AddRealmStore(new State2(), Reducers.2RootReducer);
services.AddRealmStore(new State3(), Reducers.3RootReducer);

1RealmStoreBuilder.UseRealmAsync();
2RealmStoreBuilder.UseRealmAsync();
2RealmStoreBuilder.UseRealmAsync();

This resolved the refresh problem and all panels updated independently however I need to be able to use more than one store in the components.

Do you have any suggestions as to the best way to proceed.

Thanks,

Ian

How to get state in CS file of the Layout?

Layout is inherited from LayoutComponentBase, so it can't be inherited from RealmComponent. What if I want to put some logic in layout's code behind that depends on the state?

This is how I can create conditional HTML using State.

@inherits LayoutComponentBase

<RealmStateContainer TState="WebState" Context="store">
  <ComponentTemplate>
    @{
      WebState State = store.GetState();
      Action<IRealmAction> Dispatch = store.Dispatch;
    }
    @if (State.User == null)
    {
      <LayoutView Layout="@typeof(PublicTemplate)">@Body</LayoutView>
    }
    else
    {
      <LayoutView Layout="@typeof(PrivateTemplate)">@Body</LayoutView>
    }
  </ComponentTemplate>
</RealmStateContainer>

How can I access State in the @code section?

@code 
{
  protected override async Task OnAfterRenderAsync(bool setup)
  {
    if (setup)
    {
      if (State.User == null)   // ???
      {
          navigationManager.NavigateTo("sign-in");
      }
    }
  }
}

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.