Active-CSS / active-css

The epic event-driven browser language for UI with functionality in one-liner CSS. Over 100 incredible CSS commands for DOM manipulation, ajax, reactive variables, single-page application routing, and lots more. Could CSS be the JavaScript framework of the future?
https://activecss.org
Other
42 stars 7 forks source link

Add a syntax to fetch a variable based on a string name #283

Open bob2517 opened 1 year ago

bob2517 commented 1 year ago

Currently variables written directly in HTML looks like this: {$varname}. A need has arisen for there to be an additional syntax for fetching a variable based on a string name. An old programming term for that is "variable substitution".

Something like {${$varnameString}} and {${"varname"}}.

The inner parentheses, or whatever it ends up being, would be needed in case this was needed: {${$obj.varName}}.

This would then spill over into the syntax for if statements, etc., and look like ${$varnameString} and ${"varname"}.

It would also need to work like that in run command JS blocks and {= =} JS expressions.

bob2517 commented 1 year ago

Needs to work like lodash _get() and handle complex paths, like the new getVar() helper function.

bob2517 commented 6 months ago

On review this has come up several times in development scenarios, so worth doing.

bob2517 commented 6 months ago

Note to self: There is a helper function in the docs called getVar for use in JS expressions which gets a variable value based on a path. The new syntax would be a native ACSS equivalent for use in non JS commands.

bob2517 commented 6 months ago

Do this for attribute references too, as in https://github.com/Active-CSS/active-css/issues/304