2024-12-04 02:35:06 +08:00
|
|
|
import { HttpClient } from "core/http";
|
|
|
|
import { Serializable } from "interface/serializableType";
|
2024-12-18 21:54:37 +08:00
|
|
|
import React, { createElement, memo } from "react";
|
2024-12-03 01:37:02 +08:00
|
|
|
|
|
|
|
export class Layout {
|
2024-12-18 21:54:37 +08:00
|
|
|
private readonly http: HttpClient;
|
2024-12-12 23:27:36 +08:00
|
|
|
private readonly MemoizedElement: React.MemoExoticComponent<
|
|
|
|
(props: {
|
|
|
|
children: React.ReactNode;
|
|
|
|
args?: Serializable;
|
2024-12-18 21:54:37 +08:00
|
|
|
http: HttpClient;
|
2024-12-12 23:27:36 +08:00
|
|
|
}) => React.ReactNode
|
|
|
|
>;
|
2024-12-03 01:37:02 +08:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
public element: (props: {
|
|
|
|
children: React.ReactNode;
|
|
|
|
args?: Serializable;
|
2024-12-18 21:54:37 +08:00
|
|
|
http: HttpClient;
|
2024-12-03 01:37:02 +08:00
|
|
|
}) => React.ReactNode,
|
|
|
|
services?: {
|
|
|
|
http?: HttpClient;
|
2024-12-04 02:35:06 +08:00
|
|
|
},
|
2024-12-03 01:37:02 +08:00
|
|
|
) {
|
|
|
|
this.http = services?.http || HttpClient.getInstance();
|
2024-12-08 00:55:12 +08:00
|
|
|
this.MemoizedElement = memo(element);
|
2024-12-03 01:37:02 +08:00
|
|
|
}
|
|
|
|
|
2024-12-18 21:54:37 +08:00
|
|
|
render(props: { children: React.ReactNode; args?: Serializable }) {
|
2024-12-08 00:55:12 +08:00
|
|
|
return createElement(this.MemoizedElement, {
|
2024-12-05 16:58:57 +08:00
|
|
|
...props,
|
2024-12-18 21:54:37 +08:00
|
|
|
http: this.http,
|
2024-12-05 16:58:57 +08:00
|
|
|
});
|
2024-12-03 01:37:02 +08:00
|
|
|
}
|
2024-12-04 02:35:06 +08:00
|
|
|
}
|