/******************************************************************************* * * 代理: 视图监听 * * * * 2021.12.10 ******************************************************************************/ // 功能安装 const install = function( _inst ) { // 对象非法 if( nx.dt.objEmpty( _inst ) ) { nx.error( "[视图监听插件]安装失败,对象非法!" ); return false; } // 重复安装 if( nx.dt.arrGood( _inst.lstView ) ) { nx.error( "[视图监听插件]安装失败,重复安装!" ); return false; } // 安装 _inst.lstView = []; // 视图监听 nx.dt.fnEmptyError( _inst.bindView ); _inst.bindView = function( _agent, _list ) { // 重复监听 let map = _inst.lstView[_agent.vid]; if( nx.dt.arrNEmpty( map ) ) { nx.error( "[视图监听插件]重复监听:" + _agent.vid ); return; } // 添加 _inst.lstView[_agent.vid] = _agent; _agent.vbind( _inst, _list ); }; // 视图监听全解除 nx.dt.fnEmptyError( _inst.unbindViews ); _inst.unbindViews = function() { for( let vid in _inst.lstView ) { let vw = _inst.lstView[vid]; if( vw ) { vw.vunbind( _inst ); } } _inst.lstView = {}; }; return true; }; // 功能卸载 const uninstall = function( _inst ) { // 对象非法 if( nx.dt.objEmpty( _inst ) ) { nx.error( "[视图监听插件]安装视图插件失败,对象非法!" ); return false; } // 取消监听 _inst.unbindViews(); // 卸载 delete _inst.lstView; delete _inst.bindView; delete _inst.unbindViews; return true; }; module.exports = { install, uninstall };