[API/UI]

Component

개요

Component 클래스는 component 프로퍼티에 지정한 options를 기준으로 오브젝트를 생성/실행합니다.
Component 클래스의 주요 기능은 아래와 같습니다.
1. 오브젝트(인스턴스)를 생성/실행합니다.

2. showTo에 지정한 엘리먼트를 parent 엘리먼트로 하여 컴포넌트 실행 결과가 child Element로 설정됩니다.

3. component에 구조에 따라 DOM Tree가 결정됩니다.

4. defaultCcode를 각 컴포넌트의 ccode로 설정합니다.
    - options.defaultCcode에 ccode를 지정하고 options.component에 ccode를 작성하지 않으면
      defaultCcode의 값을 ccode를 작성하지 않은 모든 계층의 options.component에 설정합니다.
    - component 계층 단위로 지정할 수 있으며 지정한 이하 계층의 모든 component에 설정됩니다.

5. 통합/융합된 컴포넌트 아키텍처와 메키니즘을 지원합니다.

6. Custom component에 MethodChain의 컴포넌트를 컴포넌트로 사용할 수 있습니다.
    - namespace(package)를 등록합니다.
    - 컴포넌트로 등록합니다.
    - MethodChain 기본 형태로 클래스를 작성합니다.
    - new my.group.myClass() options의 component에 MethodChain 컴포넌트를 ccode로 작성합니다.

    mc.namespace('my.group');
    mc.component.Code.add('mycode', 'new my.group.MyClass', 'mainMyClass');

    my.group.MyClass = function(opts){
        mc.widget.Widget.setOptions(this, opts);
        if (this.showTo) {
            this.mainMyClass(this.showTo);
        }
    };

    my.group.MyClass.prototype = {
        ccode: 'mycode',
        id: 'mycode_id',
        mainMyClass: function(showTo){
            this.showTo = showTo || this.showTo;
            mc.component.Component.isExec(this, 'mycode', this.showTo);
        },

        createMessage: function(){
        }
    }
    mc.exec(function() {
        new my.group.MyClass({
            showTo: 'showArea',
            component: [
                {ccode: 'labeltext', label: {text: '스포츠', width: 50}},
                {ccode: 'labeltext', label: {text: '책', width: 50}}
           ]
        });
    });

7. MethodChain에 Custom component를 컴포넌트로 사용할 수 있습니다.
    - 4번 사례에서 아래의 코드를 제외한 나머지 코드는 같습니다.
    - component에 ccode로 Custom Class를 작성합니다.
    - component를 실행하면서 생성한 오브젝트의 메소드를 호출할 수도 있습니다.
      ccode에 실행할 코드를 작성하면 됩니다.

    mc.exec(function() {
        new mc.panel.Panel({
            showTo: 'resultArea',
            width: 200,
            component: [
                {ccode: 'mycode'},
                {ccode: 'labeltext', label: {text: '스포츠', width: 50}},
                {ccode: "mc.component.Instance.get('mycode_id').createMessage()"}
           ]
        });
    });

8. component로 등록하지 않고 function() 형태를 지정할 수도 있습니다.
    var myOptions = function(opts){};
    var myNewFunction = function(opts){};
    var sports = {};
    sports.mySports = function(opts){};

    new mc.panel.Panel({
        showTo: 'showArea',
        width: 500,
        height: 150,
        component: [
            {ccode: myVarFunction},
            {ccode: myOptions, id: 'my_options'},
            {ccode: 'new myNewFunction(opts)'},
            {ccode: 'new sports.mySports(opts)'}
        ]
    });
Options Component
 
 
Method Component
isExec (Object, String, HTMLElement) : Boolean
isExec(that, ccode, showTo)
실행중인 컴포넌트가 마지막 클래스인 경우 mc.component.Component.exec()를 실행합니다.
options.events에 지정한 이벤트를 등록합니다.
closeOptions 이벤트를 fire시킵니다.
mc.widget.Widget.ready()에서 options.ready에 지정한 함수를 실행합니다.
Parameters :
• {Object} that, this 인스턴스
• {String} ccode, 비교할 ccode
• {HTMLElement} showTo, 컴포넌트의 parent element
Returns :
• {Boolean} isExec 실행결과
ccode에 지정한 컴포넌트가 마지막으로 실행하는 컴포넌트이면 true를 아니면 false를 반환
component.Component
실행중인 컴포넌트가 마지막 클래스인 경우 mc.component.Component.exec()를 실행합니다.
isGroupExec (Object, String, HTMLElement)
isGroupExec(that, ccode, showTo)
RadioGroup과 같이 클래스 내부에서 반복하여 Componet 인스턴스를 생성하는 경우에 사용합니다.
Parameters :
• {Object} that, this 인스턴스
• {String} ccode, 비교할 ccode
• {HTMLElement} showTo, 컴포넌트의 parent element
Returns :
• 없음
component.Component
RadioGroup과 같이 클래스 내부에서 반복하여 Componet 인스턴스를 생성하는 경우에 사용합니다.
isOwn (Object, String) : Boolean
isOwn(that, compare)
this.ccode가 최종적으로 실행하는 클래스 여부를 체크합니다.
다른 클래스에서 extend()하면 ccode가 오버라이드되므로 최종 클래스가 되지 않으며, 다른 클래스에서 new로 생성한 경우 다른 클래스의 부속 역할을 하므로 최종 컴포넌트가 될 수 없습니다.
Parameters :
• {Object} that, this 인스턴스
• {String} compareCcode, 비교하려는 ccode
Returns :
• {Boolean}
component.Component
this.ccode가 최종적으로 실행하는 클래스 여부를 체크합니다.
Custom Event Component
ready () component.Component
options 설정을 완료 했을 때 fire됩니다.
Examples  
component  
Custom 컴포넌트가 주체가 되어 MethodChain의 컴포넌트를 사용한 형태입니다.
ccode  
MethodChain이 주체가 되어 Custom 컴포넌트를 사용한 형태입니다.
function  
컴포넌트로 등록하지 않고 Custom function()을 콤포넌트로 사용할 수 있습니다.
extend  
extend()를 사용하여 클래스를 상속(inheritance)받을 수 있습니다.