項目的 Demo 在 http://juy.fm 仁烹。
今天以夯實基礎(chǔ)為主陋气,深入理解一下 Meteor 中的幾個重要概念及語法最爬,尤其是 Latency Compensation。
之前的代碼是通過客戶端直接對數(shù)據(jù)庫操作來存儲反饋淹冰,正好看到一篇好文討論 使用 Client-Side Operations 和使用 Methods 的優(yōu)劣——結(jié)論是生產(chǎn)環(huán)境中始終使用 Methods叮喳,同時也引出了 Latency Compensation 相關(guān)內(nèi)容被芳。
重構(gòu)過程并不難,先注釋掉 Feedbacks.allow({ insert: function() {} }) 部分馍悟,然后把之前客戶端操作數(shù)據(jù)庫的代碼邏輯包裝在 Meteor.methods() 中畔濒,最后通過 Meteor.call() 調(diào)用之。
- Meteor Methods vs Client-Side Operations
- An Introduction To Latency Compensation
- Advanced Latency Compensation
Github 地址:使用 Methods 取代客戶端插入數(shù)據(jù)