javascript - Ensure a certain line of code is evaluated early enough -
i need set default timezone moment calls in app's lifetime, logical thing put setter in entry point file, turns out not first thing evaluated. 1 of reducers has moment().format()
it's initial state, , it's evaluated before entry point. therefore, resulting datetime string has incorrect offset.
is there way ensure code gets evaluated before other? initial state issue can solved replacing object function, still wonder how approach solving such issue.
you shouldn't relying on execution order of disparate sections of code. if work in moment (pun intended), you're creating situation destined cause bugs down line due unrelated refactor or feature add elsewhere.
instead, write middleman function returns moment you, tz set correctly. like;
momentwithtz () { return moment().tz("america/los_angeles"); }
and use instead of traditional moment
in rest of code, ensuring tz set explicitly instead of trusting set else unrelated.
Comments
Post a Comment