PardusLabs.NuFlexiArch
1.0.9.4
Scope has been reduced
dotnet add package PardusLabs.NuFlexiArch --version 1.0.9.4
NuGet\Install-Package PardusLabs.NuFlexiArch -Version 1.0.9.4
<PackageReference Include="PardusLabs.NuFlexiArch" Version="1.0.9.4" />
<PackageVersion Include="PardusLabs.NuFlexiArch" Version="1.0.9.4" />
<PackageReference Include="PardusLabs.NuFlexiArch" />
paket add PardusLabs.NuFlexiArch --version 1.0.9.4
#r "nuget: PardusLabs.NuFlexiArch, 1.0.9.4"
#addin nuget:?package=PardusLabs.NuFlexiArch&version=1.0.9.4
#tool nuget:?package=PardusLabs.NuFlexiArch&version=1.0.9.4
NuFlexiArch + JSVaporizer
NuFlexiArch + JSVapor is an experimental, lightweight framework for building interactive web applications using C# and WebAssembly, without relying on higher-level abstractions like Blazor. It provides:
- A component model (
NuFlexiArch
) to define and manage UI components, their data, and metadata. - A renderer and DOM interop layer (
JSVapor
) to generate HTML, manipulate the DOM, and manage events directly through[JSImport]
and[JSExport]
. - A transformer system for converting DTOs (data transfer objects) to JSON or views, supporting a registry of transformers.
The goal is to give developers fine-grained control over the DOM while avoiding large amounts of “spaghetti JavaScript” by writing most application logic in C#.
Table of Contents
Features
- C#-First Approach: Consolidate your UI logic, event handling, and rendering in C#.
- Component Architecture: Build components that inherit from an abstract
AComponent
and manage their own state (CompDataDto
) and metadata. - Custom Rendering: Render HTML through
IComponentRenderer
implementations that generate DOM elements on the fly. - Fine-Grained DOM Control: Use
[JSImport]
calls for direct DOM manipulation with minimal overhead or abstraction. - Event Handling: Attach C# event handlers to DOM events via an event pool, eliminating the need for raw JavaScript event listeners.
- DTO to JSON: Serialize and deserialize component state with strongly typed data-transfer objects using System.Text.Json source generation.
- Registry & Transformers: Dynamically switch between transformers to convert JSON strings into component DTOs (or vice versa).
Project Structure
This framework is split across three main namespaces (and corresponding files/folders):
NuFlexiArch
- Defines the core abstractions for components (
AComponent
,IComponentRenderer
,CompDataDto
, etc.) - Handles serialization/deserialization (
CompMetadata
,CompInstanceDto
, JSON contexts).
- Defines the core abstractions for components (
JSVNuFlexiArch
- Contains concrete WASM-focused components (e.g.,
JSVSlider
,JSVTextDisplay
) that build uponNuFlexiArch
. - Uses the
JSVapor
API to create DOM elements, attach events, etc.
- Contains concrete WASM-focused components (e.g.,
JSVapor (or JSVaporizer)
- The low-level DOM interop layer for .NET WASM.
- Provides classes like
Document
,Element
,Window
and direct[JSImport]
references to JavaScript. - Manages event listener pools and function pools to coordinate DOM events and callback invocation in C#.
Getting Started
Prerequisites
- .NET 7 (or higher) SDK
- A browser environment that supports WebAssembly and the new
System.Runtime.InteropServices.JavaScript
features.
Cloning the Repository
git clone https://github.com/PardusLabs/JSVaporizer-NuFlexiArch.git
cd NuFlexiArch-JSVaporBuilding
- Open the solution (or project) in Visual Studio / VS Code / JetBrains Rider.
- Build the project. This should produce a WASM application that you can serve or run.
Running
Depending on your setup, you might have a
dotnet run
project or a static host for the generated WASM.In many .NET WASM templates, you’ll do something like:
dotnet run --project MyWasmProject
Then navigate to the displayed local URL (e.g.,
https://localhost:5001
).
Creating a Custom Component
- Inherit from
AComponent
(or a specialized base likeASlider
). - Define your own DTO class (e.g.
public class MyCompDataDto : CompDataDto { ... }
). - Provide an implementation for
UpdateState()
andGetState()
. - Optionally override
Initialize()
to attach event listeners or do post-render actions. - Create a matching renderer implementing
IComponentRenderer
(or extendJSVComponentRenderer
).
- Inherit from
How It Works
Define a Component
- For example,
JSVSlider
inherits fromASlider
. It keeps track of_value
,_labelValue
, etc.
- For example,
Render to the Browser
- A
JSVSliderRenderer
creates the HTML markup for your slider. - You call
JSVapor.Document.CreateElement
, set properties, add attributes, etc. - The markup is placed in the DOM by calling
AppendChild
or settinginnerHTML
.
- A
Attach Event Handlers
- In
Initialize()
, a slider can register a "change" listener to update the C#_value
. - This uses
JSVapor.Element.AddEventListener
plus the event poolWasmJSVEventHandlerPool
.
- In
Update State
- When an event triggers, the component updates its internal data.
- Any secondary UI (e.g., a text display showing the slider value) can be synced as well.
Serialize / Deserialize
- If needed, the component’s
CompDataDto
(e.g.SliderDataDto
) can be serialized to JSON. - This enables storing/restoring UI states or sending state to other services.
- If needed, the component’s
Roadmap
Additional Components
- Buttons, dropdowns, text inputs, checkboxes, etc.
Lifecycle Hooks
- Provide a more robust lifecycle (e.g.,
OnRender
,OnAfterRender
,OnDispose
) for better resource management.
- Provide a more robust lifecycle (e.g.,
Routing / Navigation
- Potentially integrate with a lightweight routing system.
Improved Error Handling & Logging
- More graceful handling of DOM operations or events that fail.
Tooling / CLI
- Possibly a CLI or templates for easier scaffolding of new components.
Contributing
We welcome contributions, whether it’s fixing bugs, adding features, or enhancing documentation!
- Fork & Clone the repo.
- Create a Branch for your feature or fix.
- Commit & Push your changes.
- Create a Pull Request against the main branch.
Please follow any existing code style guidelines and ensure all new code is well-documented.
Enjoy building UI in .NET with direct DOM control! Let us know how you use NuFlexiArch + JSVapor in your own projects.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|