==由於Node.js出現而衍生的前端框架逐漸走向成熟,各個框架以前互相借鑑良好的編程思想已經成爲常態,目前React與Vue分別都有Redux,Vuex工具來管理應用程序數據狀態,惟獨Angular沒有出現成熟穩定的狀態管理工具,雖然NGRX是專門爲Angular設計,可是其上手較難,因此本人不想使用,因此仍是使用比較熟練的RXJS來定製.==前端
cancellation.data.service.ts編程
@Injectable() export class CancellationDataService { cancellData: CancellationInfo; constructor() { } /** * When access the page each time, then need initial Center Data. */ initPoAdjusterData(): CancellationInfo { this.cancellData = new CancellationInfo(); return this.cancellData; } }
@Injectable() export class CancellationStateService { mainSubject: Subject<ActionConstucter>; constructor() { } initMainSubject() { this.mainSubject = new Subject<ActionConstucter>(); } /** * Dispatch one action */ dispatchAction(actionType: Action) { const callAction = new ActionConstucter(actionType); this.mainSubject.next(callAction); } /** * Dispatch multiple actions at the same time. */ dispatchActions(lstSubjectInfo: ActionConstucter[]) { _.each(lstSubjectInfo, (subjectInfo: ActionConstucter) => { this.mainSubject.next(subjectInfo); }); } /** * When portal destory, then unsubscribe */ unsubscribeMainSubject() { this.mainSubject.unsubscribe(); } }
/** * operation action subject (for containing each action type) */ export type Action = 'QueryResult' | 'ReprocessException' | 'ReFreshCancellation' | 'ReFreshReschedule' /** * refresh cancellation reschedule two tab at the same time */ | 'ReFreshCancellReschedule' /** * refresh queryResult's tab number (cancellation,reschedule,new po,exception) */ | 'RefreshTabTotalNumber' /** * refresh New order todo table and submit table data */ | 'ReFreshNewOrder' /** * refresh manual creation return list data * and create template data Source(like material...) */ | 'RefreshManualCreation' /** * get Material list for create po template material option */ |'RefreshPurchasingList' // New PO Submit List Submit Refresh PurchasingList;
export class ActionConstucter { actionType: Action; constructor(actionType: Action) { this.actionType = actionType; } }
subscribeAction() { const { mainSubject } = this.stateSvc; mainSubject.takeUntil(this.compInstance.destroy$) .filter(item => item.actionType === 'QueryResult' || item.actionType === 'ReFreshCancellation' || item.actionType === 'ReFreshCancellReschedule') .subscribe((item) => { this.refreshUI(); }); }
this.stateSvc.dispatchAction('ReFreshCancellReschedule');
refreshUI() { this.compInstance.UICtrl = new UICtrlInfo(); this.compInstance.UIDisplay = new UIDisplayInfo(); this.compInstance.UIJsPanel = new CancellationTableJspanelInfo(); this.closeAllExpand(); const { cancellData } = this.dataService; this.compInstance.UICtrl.categoryTypeList = cancellData.categoryTypeList; this.compInstance.UICtrl.categoryCodeMap = cancellData.categoryCodeMap; const cancellationList = this.compInstance.submit ? cancellData.cancellationList.cancel_submit : cancellData.cancellationList.cancel_to_do as CancellationTableInputConfig[]; if (!_.isEmpty(cancellationList)) { this.compInstance.UIDisplay.lstData = this.getContentList(cancellationList); this.cfgSvc.refreshStatus(); } }
const { cancellData } = this.dataService; this.compInstance.UICtrl.categoryTypeList = cancellData.categoryTypeList; this.compInstance.UICtrl.categoryCode