NGXS state size and performance - redux

I'm impressed with the redux-like pattern in Angular, and I'm hooked into NGXS (I compared this with NGRX and Akita, but opted for NGXS).
I'm aware that NGXS stores all the previous states within the application, so if I've a very complex UI, with tons of grid manipulations, etc which on each action adds a new state, won't the global state object becomes 'very large' and bulky with the entire hierarchy of the previous states ?
Is there a performance issue with this as the application gets complex and complex ?

NGXS does not store the previous states of the application.
When you add the Dev Tools Plugin and open the Redux Dev Tool then each change to the state is sent to the Redux Dev Tool. It would be the Dev Tool that stores the previous application states.
As the application state tree gets bigger the only performance hit you would see would be when you have your Redux Dev Tools open. Other than that it is entirely dependent on how you design your state and selectors.

Related

Options for State Management in Blazor

What libraries/techniques are available in Blazor for State management for webassembly (wasm).
It would be nice to know pros and cons of different approaches.
There are several options:
Redux (Fluxor)
Redux/Flux pattern has become a leader in state management in JS word; so it would make sense to adopt this best practice.
Luckily there is already a Fluxor library that does just that; and it does have the most github stars 379; although it is still a relatively new area; so it remains to be seen what ends up being the most adopted approach later on.
There is a great intro video along with source code
Official docs:
State, actions, and reducers
Effects
Redux Dev Tools
An in depth article.
Blazor-State
Blazor-State
Pros: uses MediatR for messaging
See also
Overviews of State Management Approaches
https://chrissainty.com/mobile-blazor-bindings-state-management-and-data/
https://jonhilton.net/blazor-state-management/
https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management
nice but mostly messaging: https://jasonwatmore.com/post/2020/07/30/aspnet-core-blazor-webassembly-communication-between-components
keywords: passing data between blazor wasm webassembly components child parent attributes events handling
A Blazor app is a C# app on top of the .Net BCL libraries. We don’t need to emulate what the JavaScript world has created to overcome its own deficiencies. C# can cache anything you want with static members.

Angular Component Library Project with NGRX?

I've used NGRX for a few projects now and generally really like it. But I'm struggling with whether or not to use it in my next project which will be to create an angular component library.
Is it recommended to use ngrx in angular library project types? How would you setup the root state vs the feature state? Would my library project's main module attach to the ngrx root store? If so then if my library is used in a parent app that is also using ngrx would the root store's collide?
Update (More Context):
The majority of the components in the library will be typical forms of data type of stuff. For example providing components to search, update, create and delete things across multiple applications. We're packaging them up as a component library (and angular elements library) because they will need to be used in multiple web applications until those web applications converge into one new super web application (time line for convergence is 1+ year down the road). The other integration path we were looking at was loading an iframe in all these client apps.
The components themselves will connect to an API layer to do all the data I/O. Components may need to share parts of state across components.
This is hard to answer without having the full context.
If we're speaking about a "pure" component library, I would rather not pull in any state management libraries. If the component needs some state, it should manage its state on its own.
Components using this library can always be in control of the communication with the store.

Using Vaadin Push to push server changes

I want to use Vaadin Push in my application. I am using vaadin 7.1.2 which has vaadin push built in. I have 2 question:
How to push the changes from the database on change in data in the database? How can I listen to the database changes? Is there any listeners in vaadin push which can be use?
Since I have many modules in my application I want to add push functionality to only selected modules. Is it possible to add push to only selected modules?
Thanks
Abhilash
Abhilash, what kind of persistence layer you are using?
Common Vaadin Container implements PropertySetChangeListener listener so you can register to and receive event for every DB change. But it will work only if you will change DB via this Container.
Well, external changes won't be noticed and no event will be provided. For this case it is a much harder to get noticed about these DB changes. You should implement kind of "middleware", which will handle all DB changes and also it will notify all registered listener.
To second question, I'm not sure what you mean with modules? Could you provide more information with examples?
How to push the changes from the database on change in data in the database? How can I listen to the database changes? Is there any listeners in vaadin push which can be use?
No, no silver bullet there.
Databases do not generally have an event-notification system to alert external systems about changes to the stored data. You need to code such behavior yourself.
Postgres NOTIFY
The Postgres database offers an unusual feature of NOTIFY where a client connected to the database server can be prodded from server-side code such as PL/pgSQL. The server-side code can ship an optional “payload” string to the client. The client-side database-connection implementation must be coded to accept such notifications.
If you have such a client, then you could do something like have triggers that fire when saving changes to certain tables, then use NOTIFY to tickle the client into querying the table name passed as the payload.
This is nowhere near standard SQL, and is a Postgres-specific feature.
Vaadin events
If the only source of changes to the database is within your Vaadin app, you could set up some kind of alert system within your app.
The ServletContext is required by the Servlet spec to represent your web app at runtime. You can get/set “attributes” as a way for the various threads and user sessions to communicate with each other.
You would need a way to track all your user sessions, as discussed here.
Taking a Vaadin-centric approach may not be practical if there is any chance of other sources of changes to the database outside of your app.
For more info on messaging between current Vaadin users, see the Broadcasting to Other Users section in Vaadin docs, as mentioned in this Answer to a similar Question.
Polling
One common solution is polling. Spawn a background thread to query the database, report findings, then sleep. Lather, rinse, repeat. Set the sleep time for the amount of time your users are willing to be out-of-date.
This kind of work is made much easier with a ScheduledExecutorService built into Java SE. Alternatively, Java EE offers an #Schedule annotation as discussed here, but I am unfamiliar with its usage. Either way, you are scheduling a chunk of code to be run repeatedly. By the way, never use the Timer class in a Servlet-based app or Java EE app.
I have used the ScheduledExecutorService successfully in a Vaadin 7 app running in Tomcat 8.5. Learn about the ServletContextListener as a place in your app to launch and shutdown your executor service. See my slides for my talk on the subject.
And be sure to never access the Vaadin user-inteface layouts and widgets from a background thread. Instead, always interact with the UI by calling access or accessSynchronously on the UI class for user-interface related changes or VaadinSession for non-user-interface related changes. Read the Accessing UI from Another Thread section of the Server Push page in Vaadin doc.
Push technology updates
Push technology has been a rapidly evolving field.
As I recall, Vaadin 8 may be much more efficient with Push than Vaadin 7, though I do not recall details. At the very least, Vaadin 8 may be using more recent versions of the Atmosphere library that powers Vaadin Push features. So if possible, you may want to consider migrating to Vaadin 8. Keep in mind that Vaadin 8 has a compatibility layer feature to make it easier for you to bring over Vaadin 7 code.
Most crucial, be sure to use the latest versions of your web container such as Tomcat or Jetty. The support for WebSocket in particular has had significant improvements over the years.
While perhaps not yet ready in practice, the Servlet 4 spec has major implications for the future of Push technology. The spec includes support for HTTP/2 and Request/Response multiplexing to help with server-side push.
Vaadin Push scoped to UI
Since I have many modules in my application I want to add push functionality to only selected modules. Is it possible to add push to only selected modules?
Enabling Push significantly alters your deployment situation, and so you are wise to carefully consider its use.
Vaadin’s support for Push is scoped to your subclass of UI. Your Vaadin app by default has a single UI object for each user, from a single subclass of UI class. But your are free to instantiate additional UI objects within your user’s session. The instances may come from your same UI subclass, or from additional UI subclasses you have authored.
This is precisely how the multi-window/multi-tab support works in Vaadin 7 and Vaadin 8: You instantiate a new UI subclass object and install it into the new web browser window or tab.
I am not sure, but you may be able to swap out a Push-enabled UI object for an alternative non-Push-enabled UI object within the same web browser window/tab. But I have not tried doing so, and I do not know if this is supported or recommended. Personally, I would choose to keep the same UI object installed for the entire life of the window/tab.

Workflow design advice for ASP.Net web application?

My team has been tasked with designing a web application that is workflow driven. I need some advice regarding the design.
The workflows need to be dynamic. Meaning, users can define the workflows through some interface and apply those workflows to a given scenario (The definitions will live in a SQL 2008 Database). The scenarios are defined by the business and will never change. So there may be only 2 types of scenarios a workflow can be defined for. The workflows are not necessarily linear. Some sort of state will drive the workflow. States will also be dynamic, but only exist in a workflow.
I have been looking at examples of workflows and state machines and my head is spinning. I am not sure I want o leverage Workflow Foundation or something we develop. I have seen this and think it may work, but I am not sure the state full implementation will work for us.
You can do this using WF4. I have never used Objectflow so I can't really comment on that but it appears to be an in memory solution and with an ASP.NET web site hosted in IIS that means you will occasionally lose state as IIS recycles and AppDomain. Usually not a big problem as it doesn't happen often but a WF4 InstanceStore will take care of that. It will also allow you to run on a web farm without sticky sessions and have the workflow migrate from machine to machine.
Another nice thing is the workflow designer. Its a WPF control you can rehost in your own app. Not in am ASP.NET or Silverlight app but you can provide a smart client to have users update the workflow definition using the sane designer as you use in VS2010.
The biggest problem with WF4 is the asynchronous execution nature. You will need to use a SynchronizationContext to execute the activities and wait for the workflow to go idle in the new state before you return the resulting HTML to the browser.

Alternatives to Windows Workflow Foundation?

I've been using WWF for a while as part of an internal call center application (ASP.NET), and while learning it was a good practice in understanding how a state machine based workflow system should work, I am definitely not in love with WWF itself. In my opinion it is:
Overly complex, especially for use within web apps (all that threaded runtime stuff)
Immature (ever worked with that horrible designer?)
Anemic in its current feature set
Does anyone have a suggestion for a better .NET based workflow framework? Specifically, I am looking for the following features:
State machine based (mapping states to available actions)
A focus on user permissions (controlling who has access to what actions)
The ability to run workflows as timed background tasks (for example, to send out reminders for items that have been sitting in a certain state for x days)
That's really all I need. I don't need to be able to "drag and drop" any activities or visually design the flow. I am perfectly comfortable writing actual code once a particular action is triggered.
You could try Simple State Machine. You would have to implement access control and background timers yourself, but that shouldn't be a big deal. SSM was also built out of frustration with WF. There are some other state machine implementations on Codeplex as well. If one of them doesn't fit he bill out of the box, they are open source and should get you close enough.
I wholeheartedly agree with you about state machines in WF - they aren't testable, are too complicated, the threading model is peculiar and hard to follow, and I'm not sure a visual designer could have been more poorly conceived for designing state machines graphically. I think this may be because the state machine concept feels tacked onto the WF runtime, which was designed for sequential state machines, something WF does a much better job with, in my opinion. The problem is that state machines are really not the same animal as a sequential work flow, and should have been given a first class implementation of their own, because the warping of WF to make it seem to support them turned out to be more or less unsupportable, if not actually unusable.
I would stay away from Drools.Net since it's last SVN commit was in September 2007. Looks nice but it seems a bit too risky to make such a big library part of your project when you know it doesn't get any attention anymore.
Try Drools.NET
Have a look at Workflow Engine. It is a lightweight workflow framework for .NET and Java solutions. It has an HTML5 visual designer, version control, a decent UI and supports a wide range of databases.
Do you have the option to consider BizTalk Server?
I quite enjoyed working with Oracle BPEL Process Manager. It's part of JDeveloper.
http://www.oracle.com/technology/bpel/index.html
http://gemsres.com/story/dec06/313602/jellema-fig1.jpg
You may want to take a look at Jazz - http://jazz.codeplex.com/
Try WF4.5. It was completely redesigned since .NET4.0.
First of all you should look for a engine supporting BPMN. BPMN is a standard in Workflow and Process management and well supported from a lot of projects.
Second you should think about the requirements to thus an engine.
When you look for a BPMN Engine, there are two different approaches:
Task-Orientated
These engines (e.g. JBoss BPM - jbpm) are designed to process an input data by a well defined process model. Each task in the model gives the control to a piece of code - either a standard or an individual implementation. The process ends when the process-token reaches the end of the process model (End-Event). This kind of processing takes milliseconds. The engine can be used for batch jobs or processing data with a complex process orientated flow.
Event-Driven
Human-Centric workflow engines are event driven (e.g. Imixs-Workflow). This is a kind of state machine but offers typically much more functionality. You can start a new processinstance by assigning your business object with the initial task (defined by the start event). Than the workflow engine allows you to trigger events assigned to each task, defined in your model. Each event (Intermediate CatchEvent) triggers the workflow engine to transfer the running processinstance to the next task (state). Until no new event is triggered, the processinstance 'waits' in the current task (state). An approval process is an typical example for this kind of human-centric workflow.
You can find a list of engines here.

Resources