petukhov / super-tetris Goto Github PK
View Code? Open in Web Editor NEWImmutable Tetris in Clojure with a surprise
Immutable Tetris in Clojure with a surprise
super-tetris.core
命名空间中的animation-loop
函数里面,我猜你希望的是events-chan
中有事件到达的时候,这个函数执行一次。但是事实是,这个函数在没有事件到达时,也在不停的执行。问题出在 alts!
函数的使用上,这里需要的应该是从 events-chan
中取出事件数据,<!
函数才是合适的。animation-loop
的方式循环,我认为用(go (loop ...))
语句更为合适,可以试试用这段代码:(go
(loop [state initial-state]
(let [last-event [(<! events-chan)]
{:keys [should-rerender? new-state]} (update-state-after-event state last-event)]
(.requestAnimationFrame js/window #(when should-rerender? (render new-state)))
(recur new-state))))
替换:
((fn animation-loop [state]
(go
(let [last-event (alts! [events-chan] :default :nothing)
{:keys [should-rerender? new-state]} (update-state-after-event state last-event)]
(when should-rerender? (render new-state))
(.requestAnimationFrame js/window (partial animation-loop new-state)))))
initial-state)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.