What is XScript?

XScript is a language that helped you to be able to search and modify diagrams, tables, and columns for the user eXERD file directly.

The basic strategy

XScript has been designed on the assumption that the behavior have the following two processes :
  1. selecting the subject : Select model to control.
  2. describing the verb: Describe action for selected model.

Selecting subject

When selecting a subject, use select() statement and pass a closure as an argument. The closure should be the format that has one parameter and returns true/false. The structure of the closure is as follows:
function(it){
	return true or false;
}
All the models constituting eXERD documents are passed as the parameter of the closure ¡®it¡¯, and if the closure returns true, that model is selected. For example, below is the method to select all the columns :
select(function(it){
	return it.get("type") == "column";
})
As a result of the above code, every model whose property is "column" is selected. Here, the models selected by using "select(conditional function())" are called "model context".
It is not compulsory to use it as the parameter of the closure; It is okay to use other variable names.

Describing the verb

Now that the models to perform the task have been selected, it is time to describe behavior. Let¡¯s get started with a simple example to print out all the column names:
select(function(it){
	return it.get("type") == "column";
}).each(function(it){
	log(it.get("logical-name"));
});

The function "each(closure)" lets all the elements that belongs to a model context perform the given closure behavior in terns. (It is helpful for understanding to remind the Visitor Pattern.)