idk
This commit is contained in:
parent
d9cf50eec1
commit
bb9b300d6f
9 changed files with 83 additions and 31 deletions
|
|
@ -1,11 +1,28 @@
|
|||
import { Type } from "../index.js"
|
||||
import { Properties } from "../types/properties/components.js"
|
||||
import { Binding } from "../types/properties/value.js"
|
||||
|
||||
export function FormatProperties(properties: any) {
|
||||
const property_bags: Record<Binding, any> = {}
|
||||
|
||||
for (const key in properties) {
|
||||
const value = properties[key]
|
||||
|
||||
if (key.startsWith("#")) {
|
||||
property_bags[<Binding>key] = value
|
||||
delete properties[key]
|
||||
}
|
||||
}
|
||||
|
||||
if (properties.anchor) {
|
||||
properties.anchor_from = properties.anchor_to = properties.anchor
|
||||
delete properties.anchor
|
||||
}
|
||||
|
||||
if (Object.keys(property_bags))
|
||||
if (properties.property_bags) {
|
||||
properties.property_bags = { ...property_bags, ...properties.property_bags }
|
||||
} else {
|
||||
properties.property_bags = property_bags
|
||||
}
|
||||
|
||||
return properties
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import { UI } from "../components/UI.js"
|
||||
import { Renderer } from "../types/enums/Renderer.js"
|
||||
import { Type } from "../types/enums/Type.js"
|
||||
|
||||
export const Memory = {
|
||||
cache: new Map<string, { namespace: string; elements: Map<string, UI<any>> }>(),
|
||||
cache: new Map<string, { namespace: string; elements: Map<string, UI<Type, Renderer | null>> }>(),
|
||||
|
||||
register_ui(path: string, element: UI<any, any>) {
|
||||
register_ui(path: string, element: UI<Type, Renderer | null>) {
|
||||
const { elements: saver, namespace } = this.get_file(path, element.namespace!)
|
||||
|
||||
if (saver.get(element.name!)) {
|
||||
|
|
@ -15,11 +17,22 @@ export const Memory = {
|
|||
return namespace
|
||||
},
|
||||
|
||||
gen_ui_file_content(namespace: string, elements: Map<string, UI<Type, Renderer | null>>) {
|
||||
return JSON.stringify(
|
||||
{
|
||||
namespace,
|
||||
...elements.toJSON(),
|
||||
},
|
||||
null,
|
||||
4
|
||||
)
|
||||
},
|
||||
|
||||
get_file(path: string, namespace: string) {
|
||||
let cached = this.cache.get(path)
|
||||
|
||||
if (!cached) {
|
||||
cached = { namespace, elements: new Map<string, UI<any>>() }
|
||||
cached = { namespace, elements: new Map<string, UI<Type, Renderer | null>>() }
|
||||
this.cache.set(path, cached)
|
||||
}
|
||||
|
||||
|
|
|
|||
11
src/compilers/PreCompile.ts
Normal file
11
src/compilers/PreCompile.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
declare global {
|
||||
interface Map<K, V> {
|
||||
toJSON(): Record<string, V>
|
||||
}
|
||||
}
|
||||
|
||||
Map.prototype.toJSON = function () {
|
||||
const obj: any = {}
|
||||
this.forEach((value, key) => (obj[key] = value))
|
||||
return obj
|
||||
}
|
||||
7
src/compilers/RunEnd.ts
Normal file
7
src/compilers/RunEnd.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { Memory } from "./Memory.js"
|
||||
|
||||
process.on("beforeExit", () => {
|
||||
Memory.cache.forEach(({ elements, namespace }) => {
|
||||
console.log(Memory.gen_ui_file_content(namespace, elements))
|
||||
})
|
||||
})
|
||||
Reference in a new issue