Basic sample

The most important type in Linquid is UI<A> which represents action that performs UI layout
and produces a value of type A. UI actions can be combined either by calling methods of UI<A>
or writing a LINQ query. Before digging in deeper, let's take a look at the following piece of code:

public class Samples
	public static UI<Source<string>> Sample1 =
		from text in UIM.Input()
		let doubledText = 
			from s in text
			select s + s
		from _ in UIM.Output(doubledText)
		select doubledText;

Here, Sample1 is an UI action that produces a value of type Source<string>. Source<A> is another important
type in Linquid. It represents a reactive value, which keeps updated all the other sources connected to it.
Sources also can be manipulated using LINQ queries.
Now, let's take the query apart line by line:

from text in UIM.Input()
UIM is a container for basic UI actions. Its method Input generates an action of type UI<Source<string>>, which is
executed by creating a text box and propagating changes made to its content using a source of strings, which
is assigned to the variable text.

let doubledText = from s in text select s + s
This line produces a new source, which value is the output of text added to itself.

from _ in UIM.Output(doubledText)
Then, the resulting source is feeded to the output action, which displays the value of the source doubledText
each time it is updated.

select doubledText;
And finally, doubleText is used as the result of the whole action.

After action is created it can be executed by passing a control to its Run method. For example, to apply the action
to a form, the following code can be used in its constructor:

The result should look like this:


Last edited Oct 6, 2008 at 9:24 AM by Yuuki, version 9


No comments yet.