intoday's video, I'm goingtobedoing a reviewof a projectsenttomeby a viewer, and I'm goingtobetalkingaboutallthedifferentthingsthat I wouldchangetocleanupthecodeandmakeiteasiertoworkwithandunderstand.
Ifyouwannahaveyourprojectreviewedin a similarvideotothis, makesuretosendme a linkonTwitteratDeadofSimplified, orleave a commentdownbelowwith a linktoyourproject.
Downhere, yougetsomeinformationabouttheactualtransactions, suchasif I changethisnumber, youcouldseeitupdatesinrealtimeandalsoifwewantedtoenterin a additionalsum.
Wasthatvariabledownhereforusnowthatwehave a littlebitofanunderstandingofwhatthecodedoes.
I wouldtalkaboutthefirstthing I wouldchange, whichistheusageofstripeinthisapplication.
Stripehas a couplewaysthatyoucanuseitonewhichisjustthedefaultcheckout, whichiswhatthey'reusinghere.
Butthere's anotherway, whichis a customcheckout, whichallowsyoutocookupyourownbuttoninsteadofhavingtoremovethestripedbuttonandthenaddyourownbuttonSowecancompletelyremoveallofthiscodetoremovethedefaultbuttonandaddintheotherstripewayofdoingthingswhich I alreadyhaveentirevideodedicatedon.
Socheckthatoutisgoingtobelinkedinthecardsofabove, and I'm notgonnafocusanymoreonwhat I woulddoforthestrikechangesjustbecause I have a wholevideoalreadydedicatedthatthenextmostimportantthing I thinkwecandotocleanupthiscodeistotakethisupdatetotalfunctionandbreakitoutintomuchsmallerpieces.
Oneoftheeasiestthings I canseeisthismissionmultiplierisalwaysgoingtobe a constantvariablebasedonthisusinggasolinevariable, andwecaneasilybreakthisintoitsownfunctionbecausewe'reprobablygoingtobeusingthisinotherplacesinourapplication.
Sowejustwannahaveoneeasyfunctionwecangetthisfrom, Solet's create a functionandwhatwe'regonnacallit, get a missionmultiplier, andthisisnotactuallygoingtotakeanyparameters.
Totalfunctionistocreate a functionforupdatingforexample, thisTheoto a missionvaluesowecanjustcreateanotherfunctionherewouldjustcallitupdatemissiontext.
SoitwasTake a lookatourcoderealquickandoh, I seerightawaythatwedidn't changethesegasolinemultiplieranddieselmultiplyvariablestotheconstantvaluesthatwecreated.
Solet's changethose, saveitandgobacktoourapplicationnowandnowifweupdatethisleadervalue, weseethatour C 02 tonvalueisbeingupdated, whichisperfect.
Sincewedistractthisinto a variabledon't adeventlistenerandwewanttodooninputwewanttocall a function, andinsidethisfunctionwe'regoingtodoexactlywhatwasinthatcode.
Youcanseethat I haveallofthedifferentelementsonthepageextractedouthereintodifferentvariablessothatwecanusethemlateronwithouthavingtorepeatanyofthesedifferentstrings.
So, forexample, theideaofthiselementchangestoemoneytolateron.
Andtheonlytimethatwe'reevergettinganactualtotalamountcalculationanddoinglogicandgettingback a numberiswhenweareclickingthebuttontosubmittheformandwe'regettingthetotalamountthen.
Sothatwaywecansendthattoourserver, whichwillhandlethepaymentsforusandthen I have a bunchofdifferentfunctionsdownhere.
Forexample, thisgettotalamountisthemostcomplexfunction, andallitdoesiscall a bunchofdifferenthelperfunctionsthatgettheamountsforusandturnedthatamountfromleadersandtheleaderfueltype.
And a lotoftimesthey'reabletocallthesehelperfunctionsthatwecreated, suchasgettingtreeamount, whichis a fairlylargefunctionhere, anditjustcallsitandwedon't havetorepeatthatlogiceverytimewewanttoupdatethetreetext.
Sincewehavethissmallerhelperfunctionandwehavethatforallthedifferentwaysofuppingthetextinsteadoftheapplicationandthendownherewehave a togglefueltypebutton.
Onefinalnotethat I wanttomakeisthatthesefunctionsthatoverherethesenewerfunctions, thefactthattheyaresmallerandtheydoexactlyonethingmakesthemmucheasiertotest.
So, forexample, wecouldtestthisgetemissionmultiplierfunctionmanually, orwecoulddoitautomatically, whichisideal.
Wecouldwriteautomaticunittestforit.
Andsincethisis a smallfunction, thatonlydoesonething, it's incrediblyeasytotest, which, ifyouhavetestforyourcode, itmakesitmucheasiertochangeinthefuture.
Sinceyouknow, ifyoubreaksomethingimmediatelywithouthavingtomanuallytesteverything, whichmakesitveryeasytomissthings, andthat's reallyall I wouldchangeaboutthisoriginalcodeisjustbreakapartthoselargefunctionsmakingthemdoonethinginspecificwith a bunchofdifferentfunctionsthatarereallyshort.
So I hopeyouguysenjoyedListentome, rambleonaboutwhat?
I wouldchangeaboutthisproject.
Ifyoudidenjoyit, pleasemakesuretoleave a winkto a projectthatyouhavethatyouwouldlikemetoreview, because I wouldlovetotake a lookatitandmake a videoonreviewingyourprojectaswell.
intoday's video, I'm goingtobedoing a reviewof a projectsenttomeby a viewer, and I'm goingtobetalkingaboutallthedifferentthingsthat I wouldchangetocleanupthecodeandmakeiteasiertoworkwithandunderstand.
Subtitles and vocabulary
Click the word to look it upClick the word to find further inforamtion about it