#Dynamically interrogate modules and call their functions at run time

6 messages · Page 1 of 1 (latest)

woven karma
#

I am doing a system rewrite and there is a certain amount of hard coding going on. There was a not very well thought out strategy of making the front end configurable by a CRM but its a bit of a mess. I have a dev console on the app and want to make the hard coded data visible there. There is a config module that only has functions of arity/0. I want the dev console to interrogate that module at run time - get the a list of the functions, iterate over it calling them and the dump the results on the page. Is this possible in Typescript. Its kinda of a thing I would <just do> on the BEAM but ya know, other progamming languages...

limber agate
#

What about having all of these functions stored in an object that gets exported and then query the objectentries?

unreal blaze
#

modules are introspectable in javascript too without doing anything special. just import * as stuff from './your/module.js' and then console.log(stuff) (or use a for..in loop to iterate over stuff's properties and call the functions or whatever)

woven karma
#

yeah, that's what I know, but I don't know the syntax to iterate over the stuff's properties

#

so on the BEAM I call the function exports() on the module, get a list of atoms and then call apply('module_name', 'function_name', [])

#

but I don't know the syntax in TS 😉