From b6dfb87b304fe2b2b56aaf32befe58ef9c69db43 Mon Sep 17 00:00:00 2001 From: benStre Date: Mon, 4 Dec 2023 02:51:57 +0100 Subject: [PATCH] add runtime/type definition --- datex_short.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/datex_short.ts b/datex_short.ts index dd5211e0..3395deb2 100644 --- a/datex_short.ts +++ b/datex_short.ts @@ -13,6 +13,7 @@ import { getCallerFile, getCallerInfo, getMeta } from "./utils/caller_metadata.t import { eternals, getLazyEternal, waitingEternals, waitingLazyEternals } from "./utils/eternals.ts"; import {instance} from "./js_adapter/js_class_adapter.ts"; +import { client_type } from "./utils/constants.ts"; export {instance} from "./js_adapter/js_class_adapter.ts"; declare global { @@ -281,17 +282,22 @@ export function pointer(value:RefOrValue, property?:unknown): unknown { export const $$ = pointer; -type $type = Record|Promise>>; +interface $fn { + (value:T): MinimalJSRef +} + +type $type = (Record|Promise>>) & $fn; /** - * Used as shortcut for debugging, returns a Pointer or Promise + * Compiled reactivity syntax ($()) - throws an error when called directly and not compiled to $$() or always() + * Also used as shortcut for debugging, returns a Pointer or Promise * for a given id: * ```ts * const ptr: Pointer = $.AFEFEF3282389FEFAxE2; * ``` * */ -export const $ = new Proxy({} as $type, { +export const $ = new Proxy(function(){} as unknown as $type, { get(_target,p,_receiver) { if (typeof p == "string") { const ptr = Pointer.get(p); @@ -299,6 +305,12 @@ export const $ = new Proxy({} as $type, { else return Pointer.load(p) } }, + + apply() { + // TODO: change errors, not UIX specific + if (client_type == "deno") throw new Error("Experimental $() syntax is currently not supported on the backend"); + else throw new Error("Experimental $() syntax is not enabled per default. Add \"experimentalFeatures: ['embedded-reactivity']\" to your app.dx to enable this feature."); + }, })