Skip to content

Commit

Permalink
Revert some commits about SSR and refactor for adapting SSR (#519)
Browse files Browse the repository at this point in the history
* 🚧 feat: wip

* ♻ refactor: extract the CssProvider function as a base class

* ♻ refactor: refactor the dispose func of JSModule

* ♻ refactor: refactor the dispose func of JSObjectReferenceProxy

* ♻ refactor: rename dispose to unbind

* update outsideclick

* 🚧 feat: wip

* ♻ refactor(NextTickComponentBase): Use IAsyncDisposable instead of IDisposable

* 🐛 fix: Routable doesn't work in SSR

* remove srr script

* remove unused code
  • Loading branch information
capdiem authored Dec 18, 2023
1 parent b0fc4b5 commit ee52b67
Show file tree
Hide file tree
Showing 34 changed files with 185 additions and 347 deletions.
3 changes: 1 addition & 2 deletions src/Component/BlazorComponent.Web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"build:drawflow": "rollup --config rollup.config.drawflow.ts",
"build:swiper": "rollup --config rollup.config.swiper.ts",
"build:intersect": "rollup --config rollup.config.intersect.ts",
"build:resize": "rollup --config rollup.config.resize.ts",
"build:ssr": "rollup --config rollup.config.ssr.ts"
"build:resize": "rollup --config rollup.config.resize.ts"
},
"author": "",
"license": "MIT",
Expand Down
25 changes: 0 additions & 25 deletions src/Component/BlazorComponent.Web/rollup.config.ssr.ts

This file was deleted.

4 changes: 1 addition & 3 deletions src/Component/BlazorComponent.Web/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as slider from "./components/slider";
import * as interop from "./interop";
import * as overlayable from "./mixins/overlayable";
import * as ssr from "./ssr";

declare global {
interface Window {
Expand All @@ -14,8 +13,7 @@ window.BlazorComponent = {
interop: {
...interop,
...overlayable,
...slider,
ssr
...slider
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class OutsideClick {
}

removeListeners() {
document.removeEventListener("click", this.listener);
document.removeEventListener("mousedown", this.mousedownListener);
document.removeEventListener("click", this.listener, true);
document.removeEventListener("mousedown", this.mousedownListener, true);
}

resetListener() {
Expand All @@ -46,12 +46,14 @@ class OutsideClick {

checkEvent(e: MouseEvent) {
return this.excludedSelectors.some((selector) => {
const el = document.querySelector(selector);
if (!el) return false;

return el.contains(e.target as HTMLElement);
const elements = Array.from(document.querySelectorAll(selector));
return elements.some(el => el.contains(e.target as HTMLElement));
});
}

unbind() {
this.removeListeners();
}
}

function init(dotNetHelper: DotNet.DotNetObject, excludeSelectors: string[]) {
Expand Down
123 changes: 0 additions & 123 deletions src/Component/BlazorComponent.Web/src/ssr/index.ts

This file was deleted.

45 changes: 0 additions & 45 deletions src/Component/BlazorComponent.Web/src/ssr/page-script.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/Component/BlazorComponent.Web/src/ssr/ssr-state-restore.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ protected BDomComponentBase()
{
_watcher = new PropertyWatcher(GetType());

CssProvider = new(() => Class, () => Style);
AbstractProvider = new();
}

Expand All @@ -24,26 +23,12 @@ protected BDomComponentBase()
[Parameter]
public string Id { get; set; } = null!;

/// <summary>
/// Specifies one or more class names for an DOM element.
/// </summary>
[Parameter]
public string? Class { get; set; }

/// <summary>
/// Specifies an inline style for an DOM element.
/// </summary>
[Parameter]
public string? Style { get; set; }

/// <summary>
/// Custom attributes
/// </summary>
[Parameter(CaptureUnmatchedValues = true)]
public virtual IDictionary<string, object?> Attributes { get; set; } = new Dictionary<string, object?>();

protected const int BROWSER_RENDER_INTERVAL = 16;

private readonly PropertyWatcher _watcher;

private ElementReference _ref;
Expand All @@ -54,8 +39,6 @@ protected BDomComponentBase()

protected ILogger Logger => LoggerFactory.CreateLogger(GetType());

public ComponentCssProvider CssProvider { get; }

public ComponentAbstractProvider AbstractProvider { get; }

/// <summary>
Expand Down Expand Up @@ -88,7 +71,6 @@ protected override void OnInitialized()
{
Id ??= ComponentIdGenerator.Generate(this); // TODO: v2 remove this?
base.OnInitialized();
SetComponentClass();
}

protected override void OnAfterRender(bool firstRender)
Expand Down Expand Up @@ -117,10 +99,6 @@ protected virtual Task OnElementReferenceChangedAsync()
return Task.CompletedTask;
}

protected virtual void SetComponentClass()
{
}

/// <summary>
/// Register watchers at the first render.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using BlazorComponent.Abstracts;

namespace BlazorComponent;

public class CssProviderComponentBase : ComponentBase
{
protected CssProviderComponentBase()
{
CssProvider = new(() => Class, () => Style);
}

public ComponentCssProvider CssProvider { get; }

/// <summary>
/// Specifies one or more class names for an DOM element.
/// </summary>
[Parameter]
public string? Class { get; set; }

/// <summary>
/// Specifies an inline style for an DOM element.
/// </summary>
[Parameter]
public string? Style { get; set; }

protected override void OnInitialized()
{
base.OnInitialized();

SetComponentClass();
SetComponentCss();
}

[Obsolete("Use SetComponentCss instead")]
protected virtual void SetComponentClass()
{
}

protected virtual void SetComponentCss()
{
}
}
Loading

0 comments on commit ee52b67

Please sign in to comment.