Daniil Korostelev
(Forge of Empires)
// data structure
class Player {
var name:String;
}
// logic entry point
class Commands {
// action
function changeName(newName) {
validateName(newName); // no swear words!
data.player.name = newName; // state change
}
}
// listen to changes
// (could also be "reactive" property or something)
logic.data.player.onNameChanged(
newName -> playerNameLabel.text = newName
);
// handle UI
function onNameEntered(input) {
// execute action
logic.commands.changeName(input)
}
function processCommand(name, args, checksum) {
// do the preparations
loadPlayerData();
startTransaction();
// call logic
var changes = logic.execute(name, args);
// consistency check
if (changes.checksum != checksum)
throw "invalid checksum!";
// save to database
commitChanges(changes);
}
Code generation for all the things!