有以上原因,本次开发需要对写好的逻辑多次的梳理重构,因而有以下的感悟
相比于在getShortcuts的回调中赋值 that.shortcuts,在接口的回调中赋值更合理些。
getShortcuts() {
var that = this;
return new Promise(function(resolve, reject) {
IMSDK.invoke("intelligentservice.GetHotKeyList").then(function(res) {
that.shortcuts = res.result;
resolve();
}, function() {
reject();
})
});
}
抽出的众多方法中,渲染函数和数据修改函数属于兄弟关系,数据修改函数和由其引起的变化属于父子关系。这样的梳理,可以使得有多个开关且异步众多的情况下,调用灵活,思维清晰。
document.getElementById("open-bar").addEventListener("click", function() {
render();
setData(0);
});
function setData(effectZnts) {
localStorage.effectZnts = effectZnts;
this.dealChanged(localStorage.effectZnts);
}