From e77caef983586bf1fe808337421a43f2ff9a72b3 Mon Sep 17 00:00:00 2001 From: Ni55aN Date: Mon, 30 Dec 2024 01:27:54 +0200 Subject: [PATCH] fix: update in angular 19 may affect any previous version --- src/core.ts | 4 ++-- src/reflect.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/reflect.ts diff --git a/src/core.ts b/src/core.ts index 4112ecb..a4ab844 100644 --- a/src/core.ts +++ b/src/core.ts @@ -4,6 +4,7 @@ import { createCustomElement } from '@angular/elements'; import { NgElement, NodeProps, Position, RenderSignal } from './types' import { RenderPreset } from './presets/types'; +import { reflect } from './reflect'; type Item = { key: string, ngElement: NgElement } @@ -39,9 +40,8 @@ function getRenderer(): Renderer { }, update({ ngElement }, props) { Object.keys(props).forEach(key => { - ngElement.ngElementStrategy.setInputValue(key, props[key]) + ngElement.ngElementStrategy.setInputValue(key, reflect(props[key])) }) - ngElement.ngElementStrategy.setInputValue('seed', Math.random()) }, unmount(element) { const existing = elements.get(element) diff --git a/src/reflect.ts b/src/reflect.ts new file mode 100644 index 0000000..5c47c41 --- /dev/null +++ b/src/reflect.ts @@ -0,0 +1,18 @@ +export function reflect(obj: unknown) { + if (typeof obj !== 'object' || obj === null) { + return obj; + } + + return new Proxy(obj, { + get(target, prop) { + return target[prop]; + }, + set(target, prop, value) { + target[prop] = value; + return true; + }, + has: (target, prop) => prop in target, + deleteProperty: (target, prop) => delete target[prop], + ownKeys: target => Reflect.ownKeys(target) + }); +} \ No newline at end of file