이벤트 설정
명령 실행, 데이터 변경, 컬렉션 변경 이벤트에 반응합니다.
모델(BindModel)은 실행 이벤트, 변경 이벤트, 컬렉션 이벤트 등 다양한 상황에서 이벤트를 설정할 수 있습니다.
실행 이벤트#
모델(BindModel)과 명령(BindCommand) 실행 전 후에 이벤트를 설정할 수 있습니다.
type onExecute = (bModel: BindModel, bCommand: BindCommand) => void;
type onExecuted = (bModel: BindModel, bCommand: BindCommand) => void;bModel: 대상의 모델(BindModel)객체bCommand: 대상의 명령(BindCommand)객체
모델 실행 이벤트#
모델(BindModel)에서 실행 전(onExecute)과 실행 후(onExecuted) 이벤트를 설정합니다. 이는 모든 명령에 적용됩니다.
const bm = new BindModel();
bm.addCommand('cmd1');
bm.onExecute = function (bModel, bCommand) {
console.log('Model: Before execute');
};
bm.onExecuted = function (bModel, bCommand) {
console.log('Model: After execute');
};
bm.command['cmd1'].execute();
// 출력:
// Model: Before execute
// Model: After execute
명령 실행 이벤트#
특정 명령(BindCommand)에만 실행 전(onExecute)과 실행 후(onExecuted) 이벤트를 설정합니다.
const bm = new BindModel();
bm.addCommand('cmd1');
bm.command['cmd1'].onExecute = function (bModel, bCommand) {
console.log('Command: Before execute');
};
bm.command['cmd1'].onExecuted = function (bModel, bCommand) {
console.log('Command: After execute');
};
bm.command['cmd1'].execute();
// 출력:
// Command: Before execute
// Command: After execute
변경 이벤트#
컬럼 변경 이벤트#
컬럼값이 변경된 후 이벤트가 발생합니다.
type onChanged = (nVal: ValueType, oVal: ValueType, _this: this) => void;
nVal: 새로운 컬럼값oVal: 이전 컬럼값
const bm = new BindModel();
bm.columns.addValue('aa', 10);
bm.columns['aa'].onChanged = function (nVal, oVal, _this) {
console.log(`New Value: ${nVal}, Old Value: ${oVal}`);
};
bm.columns['aa'].value = 20;
// 출력:
// New Value: 20, Old Value: 10
Tip 뷰(MetaView)의 컬럼(HTMLColumn) 속성은 대부분 테이블(MetaTable)을 참조합니다. 따라서 컬럼 변경 이벤트를 설정할 때 테이블의 컬럼에 정의하는 것이 더욱 직관적이며 관리에 용이합니다.
로우 데이터 변경 이벤트#
테이블(MetaTable) 또는 뷰(MetaView)의 MetaRow 데이터 변경 시 발생합니다.
type onChanging = (idx: number, nVal: any, oVal: any, _this: this) => void;
type onChanged = (idx: number, nVal: any, oVal: any, _this: this) => void;
idx: 변경된 데이터의 인덱스nVal: 새로운 값oVal: 이전 값
const bm = new BindModel();
bm.addColumnValue('aa', 10, 'cmd1', 'valid');
bm.addColumnValue('bb', 20, 'cmd1', 'valid');
const v1 = bm.command['cmd1'].valid;
v1.rows.add(v1.getRow());
v1.rows[0].onChanging = function (idx, nVal, oVal, _this) {
console.log(`Before Change - Index: ${idx}, New: ${nVal}, Old: ${oVal}`);
};
v1.rows[0].onChanged = function (idx, nVal, oVal, _this) {
console.log(`After Change - Index: ${idx}, New: ${nVal}, Old: ${oVal}`);
};
v1.rows[0]['aa'] = 11;
// 출력:
// Before Change - Index: 0, New: 11, Old: 10
// After Change - Index: 0, New: 11, Old: 10
Tip 로우(MetaRow)는 테이블(MetaTable)과 뷰(MetaView)에서 독립적으로 존재합니다. 따라서 로우 이벤트는 해당 뷰(MetaView)의 row 에 정의하는 것이 더 직관적이고 효율적입니다.
컬렉션 이벤트#
컬렉션 관련 작업 시 발생하는 공통 이벤트입니다. 다양한 컬렉션 작업(추가, 삭제, 초기화 등)에 대해 대응할 수 있습니다.
- 모델(BindModel)의 컬렉션 -
_tables: 테이블 컬렉션 -columns: 기본 테이블(_baseTable)의 컬럼 컬렉션
-items: 공통 컬럼 속성 컬렉션 -command: 명령(BindCommand) 객체 컬렉션 -fn: 사용자 함수 컬렉션- 명령(BindCommand)의 컬렉션 -
_outputs: 출력 뷰(MetaView) 컬렉션 -valid.columns, valid,rows: 유효성 검사 뷰(MetaView)의 컬럼 및 로우 컬렉션 -bind.columns, bind.rows: 서버 요청 뷰(MetaView)의 컬럼 및 로우 컬렉션 -output.columns, output.rows: 서버 응답 기본 뷰(MetaView)의 컬럼 및 로우 컬렉션 -misc.columns, misc.rows: 기타 뷰(MetaView)의 컬럼 및 로우 컬렉션
컬렉션 추가 이벤트#
컬렉션에 요소를 추가할 때 발생하는 이벤트 입니다.
type onAdd = (idx: number, elem: any, _this: object) => void;
type onAdded = (idx: number, elem: any, _this: object) => void;
idx: 추가할 요소의 인덱스elem: 추가할 요소
const bm = new BindModel();
bm.columns.onAdd = function(idx, elem, _this) {
console.log(`before : idx = ${idx}, elem = ${elem._name}`);
};
bm.columns.onAdded = function(idx, elem, _this) {
console.log(`after : idx = ${idx}, elem = ${elem._name}`);
};
bm.addColumn('aa');
// before : idx = 0, elem = aa
// after : idx = 0, elem = aa
컬렉션 삭제 이벤트#
컬렉션에 요소를 삭제할 때 발생하는 이벤트 입니다.
type onRemove = (idx: number, elem: any, _this: object) => void;
type onRemoved = (idx: number, elem: any, _this: object) => void;
idx: 삭제할 요소의 인덱스elem: 삭제할 요소
const bm = new BindModel();
bm.columns.onRemove = function(idx, elem, _this) {
console.log(`before : idx = ${idx}, elem = ${elem._name}`);
};
bm.columns.onRemoved = function(idx, elem, _this) {
console.log(`after : idx = ${idx}, elem = ${elem._name}`);
};
bm.addColumn('aa');
bm.addColumn('bb');
bm.columns.remove('bb');
// before : idx = 0, elem = bb
// after : idx = 0, elem = bb
컬렉션 초기화 이벤트#
컬렉션을 초기화 할 때 발생하는 이벤트 입니다.
type onClear = (_this: object) => {};
type onCleared = (_this: object) => {};
const bm = new BindModel();
bm.columns.onClear = function(_this) {
console.log(`before : clear`);
};
bm.columns.onCleared = function(_this) {
console.log(`after : clear`);
};
bm.addColumn('aa');
bm.columns.clear();
// before : clear
// after : clear