Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 997 Bytes

File metadata and controls

32 lines (21 loc) · 997 Bytes

Sample 2

source code
(Use npm run sample2 to run the full sample from bellow.)

This sample is nearly the same as Sample 1, but this time the HybridGeneratable is used.
With the use of a HybridGeneratable not only code can be generated but also the value that the generatable is representing.
This can be particuallarly useful when build something like a server side rendering system which needs to execute the same code on the current machine and on the web.

At first a HybridGeneratableJSON is created with the value 20.

let generatable = new HybridGeneratableJSON(20)

Logging the result of generateValue()

console.log(generatable.generateValue())

should result in 20 displayed in the console.

After updating the value of the HybridGeneratable

generatable.update(42)

the same log call should result in 42.

Next: Sample 3 - compiling and typechecking the generated code