For a game, there is some WebGLRenderer object that wraps around canvas element. There is need to update it's size when browser window size changes. Here goes my current code written using BaconJS. What do you think about it ? Would you improve it in any way or maybe do it other way? I have read that listening to resize
event is just slow for game purposes.
# Make the property of window object
rWindow = Bacon.constant window
# Sample window by tick event
sTickWindow = rWindow.sampledBy app.land.stream('tick')
# Look for width and height changes on every tick
sWidth = sTickWindow.map('.innerWidth').skipDuplicates()
sHeight = sTickWindow.map('.innerHeight').skipDuplicates()
sSize = Bacon.combineAsArray sWidth, sHeight
# Resize renderer when size is changed
Bacon.onValues rRenderer, sSize, (renderer, size) ->
# Apply size update to renderer
renderer.setSize size...
Note that app.land.stream('tick')
is basically EventStream of requestAnimationFrame
invocations.
Update
To make the understanding easier, I have made fiddle for it. Open dev console and try to resize the Result window rather then browser window.