Showmetheweatherbuttonandinsideofhere, there's alreadyquite a fewthingsthatwecanchange.
Firstofall, asyoucansee, thisisusingcallbacksandnestingmultiplecallbacksinsideofeachother, whichisalways a redflagforsomethingthatcouldbechangedbecauseitcouldleadtocallbackhellalso, we'reduplicatingourairreturnshere.
Asyoucansee, we'recheckingforanheir, andbothtimesweredoingtheexactsamethingwiththaterror, whichagainissomethingthatpromisesand a singleweightcanhelpyouavoidbeforewedivetoomuchfurtherintothisactuallayoutintheserver.
Let's lookatthesetwofunctionsgeocodeandforecast.
Theseweretofindinsideofthisutilities, soopenbothoftheseupandwhat's firstlookatthegeocodeandessentiallyallthisdoesistake a fewparameters, andthenit's goingtousethisrequestlibrary, whichworks a lotlikefetch.
It's essentiallyallowingustocallin a p I andagainit's returningthesecallbacks.
This I d doesn't reallylineupwithhisvariablenameandsayingwiththisvariablenameandthis i D.
Sowhat I didinmyexampleis I changedthesenamestobemuchmoreinlinewithwhatthey'reactuallyrepresenting.
AnotherthingtonoteisthatdocumentDiequeryselector.
Isheusedhere, eventhoughwe'rejustqueenonan I D.
SoitbebesttouseGetelementby i D insteadsowecouldchangethistogetelementby D andremovethathashtagandthatwouldworkitjust a czwellandbeslightlyfasterforyourcode.
Andif I putsomethingelsehere, I'm goingtogetairinthebrowserif I trytorunthisandit's spelledincorrectly.
Sobyhavingthisin, um, itforcesmetoalwayshave a propertywhichisdefinedonanobjectofhere.
Andthisisthebestwaytodealwiththesetypeofincomestringsoranyformofstringcomparisonwhereit's a setinstonestrength.
Youwanttousetheseconstantvariablesupheretodothat.
Andlastly, as I mentionedbefore, I renamedthesevariablesdownheresothatthey'remucheasiertoreasonwithwhatthey'reactuallyrepresentinginsideofthecodeagain, theseairreallystraightforwardchanges.
Thecodeoverallwasreallywellwritten.
Thebiggestchangeisthisindumbsection, which I thinkmakesthecodemucheasiertoreasonwithwhat's goingon, anditmakesitmuchmoreairproofinthefuture.
Youcanremovethetodoat a bunchofdifferenttoduesifyouwant, andyoucanmarktherest, completeorunmarkedthemselves, notcomplete.
Andalsoyoucandosomefilteringuphereso I cando a search.
Forexample, let's putinwhenall D's andfivesearchyou'llseeit'llautomaticallyfolkaboutLet's form a Sonowlet's lookatthecodeforhowthisworks.
It's goingheretododotJsandthiscodeis, I think, themostcomplexofallthecodeandapplicationendskindofthemessiest.
And I thinkoneofthereasonsforthatisthatthere's noclassisbeingused, andeverythingisjust a bunchofdifferentfunctionsandglobalvariablesinordertodeterminewhat's goingon.
Soasyoucansee, wehave a bunchofdifferentloadingandsavingfunctionsgettingcreatinganditbecomesreallycomplex, andcertainfunctionslikegettwoDUIsarealmostentirelyuselessbecauseallthey'redoingisreturning a variable, whichisalreadytofinduphere.
Sothisgettodoisreallydoesabsolutelynothingforus.
Andthere's quite a fewvariablesthatarelikethatinthisapplication.
Forexample, there's onecalledGetfiltersjustrighthere, andit's againreturningjust a variablefilters.
Solet's lookathow I wouldreworkthisusing a classinordertochangesomeoftheseproblems.
Listjusthandles a listoftwoDUIsandallthefunctionstodosoarebuiltintotheclassitselfinsteadofbeingthroughouttheentireobjectandtheentirefile.
Andasyoucanseewiththefilters, I brokethemoutasattributesontheactualobjectsothattheycouldbesetandgotindividuallyinsteadofhavingtocall a setfunction, whichwilltrytosetallofthematonceornoneofthematall.
Sothisjustmakesitreallyeasytosetthesedifferentfilterswithouthavingtodo a bunchofcomplexobjectmanipulation.
Wehave a listofvariablesherewithallofourdifferentcolors, andthenwhenweclickon a key, allwedoiswejustcreatethatballthatfiresacrossthescreenandplaythesoundetcetera.
Andthere's reallyonlyonethingaboutthisthat I don't like, andthatisthatthiscolor's variableisduringthedifferentcolorvaluesfromMarcieSS.
Ifweswaptheorderofthesebuttonsinthebrowser, thiswillnolongerworkproperly, anditwon't actuallysend a coloredballoftherightcolor.
Soinsteadofdeterminingwhatthecoloroftheballisbasedonthesevariables, I wanttogetthecolorfromtheactualelementthattheuserclickson.
Sowhat's looking?
How I didthatinthereworkedversionofthiscoat.
Here I havethenewversionofthecodeopen, andasyoucanseeimmediately, thatcolorlistiscompletelygone, andinsteadherewe'regettingthecolorbygoingingettingthecomputedstyleoftheactualkeythatweclickon, andwe'rejustgettingthebackgroundcolorofthatelement.