-
Notifications
You must be signed in to change notification settings - Fork 0
Advanced Key Syntax
Let us summarize all JSON key features:
1. Key Command
A simple RichJSON command that takes a object as input:
"$<command_name>:key": { ...params... }
2. Constructor
The Constructor called and joined with the given object:
normal: { "key=<class_name>": { ... } }
late: { "key==<class_name>": { ... } }
3. Inheritance
Inheritance is basically a concatenation of RichJSON commands.
They are joined from left to right, and finally the given object is joined as well:
{ "key::$ref:path/to/object, $file:path/to/file, ... <commands>": { ... } }
It’s not a coincidence that these features are listed here because yes, you can use them all at once.
But be careful: these features can only be combined in the correct order.
Let me give you some examples:
Important
If you want to know what $clone does, check out this page.
import * as RichJson from "@rjson/parser"
class Coord2() {
x = 0;
y = 0;
length_xy = function() { return sqrt(x * x + y * y); }
}
RichJson.addClassMapping("Coord2", Coord2);
{
"some_object": {
"y": 10
},
"$clone:example1=Coord2": {
"x": 20,
"y": 20
},
"$clone:example2=Coord2::some_object": {
"x": 20
}
}Note
No late applyment features were used here, except for the $clone command.
{
"some_object": {
"y": 10
},
"example1": { // "$clone:example1=Coord2"
"x": 20,
"y": 20,
"length_xy": function() { return sqrt(sqr(x) + sqr(y)); }
},
"example2": { // "$clone:example2=Coord2::some_object"
"x": 20,
"y": 10,
"length_xy": function() { return sqrt(sqr(x) + sqr(y)); }
}
}Author’s Recommendation: next read: Late Applying
Back to Repo ● Wiki Home
Copyright © Maximilian Schwarz