2
我有以下功能:打破引用透明
_processSelectedPlantWcOb: function (oSelectOb, oSetNewDates, oWpServiceOb, fnQueryDatesPlantWcOb) {
let self = this;
return oSelectOb
.map(function (oEvent) {
return oEvent.getSource();
})
.switchMap(function (oSelect) {
return oSetNewDates.mapTo(oSelect);
})
.map(function (oSelect) {
let oItem = oSelect.getSelectedItem();
let aKeys = oItem.getKey().split("/");
return {sPlant: aKeys[0], sWc: aKeys[1]};
})
.switchMap(function (oSelected) {
return fnQueryDatesPlantWcOb(oWpServiceOb, oSelected.sPlant, oSelected.sWc);
});
},
正如你所看到的最後一個參數是期望的功能和作用fnQueryDatesPlantWcOb
的實現看起來如下:
_processQueryDatesPlantWcOb: function (oWpServiceOb, sPlant, sWc) {
return oWpServiceOb
.switchMap(function (oModel) {
let oPlantFilter = new sap.ui.model.Filter("Plant", sap.ui.model.FilterOperator.EQ, sPlant);
let oWcFilter = new sap.ui.model.Filter("WorkCenter", sap.ui.model.FilterOperator.EQ, sWc);
return Rx.Observable.create(function (subscriber) {
oModel.read("/CostCenterCalendarSet", {
success: function (oData, oResponse) {
subscriber.next(oResponse);
},
error: function (oError) {
subscriber.error(oError);
},
filters: [oPlantFilter, oWcFilter]
});
});
})
.filter(function (oData) {
return oData.data.results.length > 0
})
.mergeMap(function (oData) {
return Rx.Observable.from(oData.data.results);
})
.map(function (oData) {
let oDate = oData.InspectionDate;
return new Date(oDate.getFullYear(), oDate.getMonth(), oDate.getDate());
})
.filter(function (oDate) {
let oToday = new Date();
return oDate.getTime() > oToday.getTime();
})
.map(function (oDate) {
return oDate.getTime();
});
},
,你可以請參閱參數sPlant
和sWc
將用於switchMap
函數。
我想知道的是,我打破功能範式嗎? 在我看來,我沒有打破它,因爲每當我通過相同的sPlant
和sWc
值,我會得到相同的結果,但我不確定。