Dynamic Code is an attempt to build self-changing systems in Javascript. Just like in PHP you can insert code anywhere.

That is achieved using Generatables which generate code with the dynamic content inserted at the right place.

Sample use case

Imagine having a webpage with a dynamic title. At each request, the title is fetched from the database. Dynamic Code can compile that title directly into the website and regenerate the site after the title has changed.

(Dynamic Code can and should do more than plain content injection)

Example

from Sample 3 on Github

The code describes the desired behaviour that should be executed.

1. Import a function

2. create a JSON value as parameter.

3. execute the function with the parameter

The described behaviour can now be generated to code via “generate()”.

In the last line, the function is swapped with another imported function.

This is the power of Dynamic-Code, exchanging everything anytime.

With great power comes great responsibility 🕷️

Obviously swapping functions can break everything. This is where Typescript comes to rescue, which can type-checked the new behaviour to ensure correctness.