As in the title, I have an issue with those and I need to find out what is the best way to achieve?
- App has multiple language support
- App needs to listen window resize event
- App has lots of content on single page
Normally I can listen window resize event in every component but I did this instead.
main.coffee
Meteor.startup ()->
updateWindow = ()->
w = $(window).width()
h = $(window).height()
Session.set "window",
width: w
height: h
updateWindow()
then in
app.coffee (this is the parent route holder)
React = require "react"
{div,span}= React.DOM
createContainer = require("meteor/react-meteor-data").createContainer
View = React.createClass
shouldComponentUpdate:(nextProps,nextState)->
return true
extendedProps:()->
extensions =
app: app
Object.assign {}, @props , extensions
render: ()->
if @props.userSubscriptionReady
React.cloneElement @props.children, @extendedProps()
else
div {}, "Loading"
meteorContainer = (props)->
# Set Language
currentLanguage = localStorage.getItem("lang") or app.default.language
TAPi18n.setLanguage(currentLanguage)
userSubscription = Meteor.subscribe("currentUser")
objects =
userSubscriptionReady: userSubscription.ready()
currentUser: Meteor.user() or {}
currentLanguage: TAPi18n.getLanguage()
allLanguages: TAPi18n.getLanguages()
window: Session.get("window")
return objects
module.exports = createContainer meteorContainer , View
after this you probably get the idea how I will using this; this is it
home.coffee (end)
.
.
.
# bind meteor
meteorContainer = (props)->
# Contents
contents = []
for i in [0...5]
contents.push generateEmptyContent(i)
return {
contents: contents
}
module.exports = createContainer meteorContainer , View
So the problem is when I resize the window I got different contents on every scroll event
Lets think, it could be a subscription so meteor container or/and react component would render/get data every time I resize.
I tried to stop the rendering in (normally I pass necessary props to states)
componentWillReceiveProps:(nextProps)-> **here**
and I succeed but I still didn’t stop meteorContainer to run in every resize.
So…
Is meteor can handle these kind of things( somehow are subscriptions will be debounced or ? ) or should I use different approach to pass “window/currentLanguage” values?
If the answer is the second, got any idea?
Thanks in advance