Igium.Web Examples

Examples
Location: igium / Igium.Web / Igium.Web Examples

Client-side Modules and Types

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"use strict";
go
(
    lib("Utility/Type.js"),
 
    function()
    {
        namespace("Test.Namespace",
 
            [Attribute],
            type // CustomAttribute - by convention, the type name must be present on the first line of definition, either in the form of the constructor itself or as a line comment
            (
                function CustomAttribute(param1, param2)
                {
                    this.param1 = param1;
                    this.param2 = param2;
                },
                {
                    param1: null,
                    param2: null,
                }
            )
        )
 
        namespace("Test.Namespace",                //    specifies the namespace: Test.Namespace; if the name is ommitted the all types will be defined as global types
 
            type // Class1
            (                                        //    starts a type defintion
                function Class1(value)                //    specifies the name of the type: Class1; fully qualified name of the type: Test.Namespace.Class1; the method that specifies the class name starts w/ an uppercase letter; only one class name declaration is allowed per type
                {                                    //    constructor
                    this.value = value;
                },
 
                [CustomAttribute(1, 2)],            //    using a custom attribute
                function setValue(value)            //    method definition: setValue(value); common method names start w/ a lowercase letter
                {
                    this.value = value;
                },
 
                function getValue()
                {
                    return this.value;
                },
 
                function doit()
                {
                    //console.log(922, "base", Test.Namespace.Class1.someStaticMethod());
                },
 
                [CustomAttribute(1, 2)],        //    using a custom attribute
                [Static],                        //    using multiple attribute blocks
                function someStaticMethod()        //    static method definition
                {
                    return Test.Namespace.Class1.staticValue;
                },
 
                [Static, CustomAttribute(1, 2)],//    using multiple attributes in one attribute block
                {                                //    static fieldset - defines static class fields; multiple static fieldset are ok
                    staticValue: 100,
                },
 
                {                                //    fieldset - defines class fields; multiple fieldset are ok
                    value: null,
                    value2: 5,
                }
            ),
 
            type // Class2
            (
                inherit(Test.Namespace.Class1),        //    inheritance; only single inheritance is supported
 
                function Class2(value)
                {
                    Class2.base.call(this, value);    //    Class2.base.call(this, ...) is how you call the base constructor
                    this.value2 = value + 666;
                },
 
                function doit()
                {
                    Class2.base.doit.call(this);    //    Class2.base.doit.call(this, ...) is how you call a base method
                    this.value3 = this.getValue();
                },
 
                {
                    value3: 100,
                }
            )
        ),
 
        namespace
        (
            type // PropertyTest
            (
                function PropertyTest()
                {
                },
 
                {
                    _value: 666,
                },
                [Getter], function value()
                {
                    return this._value;
                },
                [Setter], function value(value)
                {
                    this._value = value;
                },
 
                [Static],
                {
                    _svalue: 999,
                },
                [Static, Getter], function svalue()
                {
                    return PropertyTest._svalue;
                },
                [Static, Setter], function svalue(value)
                {
                    PropertyTest._svalue = value;
                }
            )
        )
    }   
)
 
//types are references by fully qalified names, e.g. Test.Namespace.Class1; creating an instance of a type is done with plain new operator:
var class1Instance = new Test.Namespace.Class1("some value");
var class2Instance = new Test.Namespace.Class2("some value");
 
//sample property usage
var pt1 = new PropertyTest();
var pt2 = new PropertyTest();
 
console.log(911, pt1._value, pt1.value);
console.log(912, pt2._value, pt2.value);
 
pt1.value = 100;
pt2.value = 200;
 
console.log(913, pt1._value, pt1.value);
console.log(914, pt2._value, pt2.value);
 
console.log(921, PropertyTest._svalue, PropertyTest.svalue);
PropertyTest.svalue = 300;
console.log(922, PropertyTest._svalue, PropertyTest.svalue);

Type Nesting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
go
(
    namespace(
 
        type // MathX
        (
            function MathX()    //    defines the global type MathX; usage: new MathX()
            {
            },
        ),
    )
 
    lib("MathX.js"),            //    in case the MathX type is defined in another file, make sure that the type will be defined before the namespace (otherwise an error will occur)
 
    namespace("MathX",            //    uses the type name as a namespace name: MathX
 
        type // Complex
        (
            function Complex()    //    defines the nested type MathX.Complex; usage: new MathX.Complex()
            {
            },
 
            [Static], function newComplex(real, imaginary)
            {
                return {
                    re: real,
                    im: imaginary,
                };
            }
        )
    )
)