presentation lodash for president - github...presentation_lodash_for_president created date...
TRANSCRIPT
![Page 1: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/1.jpg)
LODASH FOR PRESIDENTChristian Ulbrich, CDO Zalari UG
![Page 2: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/2.jpg)
AGENDA PROPAGANDA• Recap: LoDash
• Why?
• Installation
• Examples galore
• Links
![Page 3: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/3.jpg)
RECAP - LODASH
„Who has never heard of LoDash?“
![Page 4: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/4.jpg)
RECAP - LODASH• available on npm and bower
• generic JavaScript library, thus works in backend and frontend
• either load it via script tag or with a module loader of your choice
• custom builds, bundles are available
![Page 5: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/5.jpg)
WHY LODASH
„Look, I invented something…“
![Page 6: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/6.jpg)
WHY LODASH
THE WIEL!
![Page 7: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/7.jpg)
WHY LODASH
![Page 8: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/8.jpg)
WHY LODASH
• Human make errors and we don’t like to repeat ourselves over and over again
• working with declarative code enables less errors and fosters maintainability
• -> „human JavaScript“
![Page 9: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/9.jpg)
INSTALLATION
![Page 10: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/10.jpg)
EXAMPLES COLLECTIONS
• LoDash has enhanced Shortcuts for typical array functions, like _.forEach, _.map, _.reduce, _.filter
• they used to be performance optimized
• they also work on Collections (Arrays + abused Objects)
![Page 11: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/11.jpg)
FILTERING + FINDING
• _.filter returns Elements that the passed predicate is true
• _.find returns the first Element that the passed predicate is true
• brethren: _.reject, _.findLast, _.some, _.without
![Page 12: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/12.jpg)
FILTERING + FINDING
• there are some nice built-in predicate function producing functions:
• _.matches, _.matchesProperty, _.property
• lodash analyzes the signature of the passed argument to most of its collection functions and calls them appropriately
![Page 13: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/13.jpg)
FILTERING + FINDING
![Page 14: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/14.jpg)
FILTERING + FINDING
• What about combining individual functions and rules?
• How can we figure out only the names of all the presenters that obey the rule famePredicate?
![Page 15: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/15.jpg)
LODASH CHAINING
• LoDash allows for chaining of its functions via _.chain wrapper, then the value of each call is passed along the chain
• at the end of the chain, we can access the value with .values()
![Page 16: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/16.jpg)
LODASH CHAINING
![Page 17: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/17.jpg)
UTILITY FUNCTIONS
• Object manipulation: _.merge, _.clone, _.cloneDeep
• beware of different LoDash versions
• _.merge modifies the first parameter!
![Page 18: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/18.jpg)
UTILITY FUNCTIONS
• _.parseInt(numbery)
• _.snakeCases, _.startCase, _.pad
• _.inRange, _.random
![Page 19: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/19.jpg)
UTILITY FUNCTIONS
• _.isUndefined
• _.isNumber
• _.isType (Array, Date, Buffer, Integer, Object, …)
![Page 20: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/20.jpg)
UTILITY FUNCTIONS
![Page 21: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/21.jpg)
UTILITY FUNCTIONS
![Page 22: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/22.jpg)
ARRAY GOODNESS
• _.zip
• _.flatten, _.flattenDeep, _.join, _.pull, _.pullAll, …
![Page 23: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/23.jpg)
COLLECTION GOODNESS
• _.sortBy, _.flatMap, _.shuffle, _.groupBy
• _.flatten, _.flattenDeep, _.join, _.pull, _.pullAll, …
![Page 24: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/24.jpg)
HUMAN JAVASCRIPT
• META!
• whenever maintainability is more important than performance, you should write human JavaScript
• LoDash’ expressive and clever naming of functions allow to do that easily
![Page 25: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/25.jpg)
HUMAN JAVASCRIPT• simple StateMachine, has valid state transitions
• a declarative approach lets the code speak
• find returns undefined if nothing is found
![Page 26: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/26.jpg)
HUMAN JAVASCRIPT• crude indexOf syntax with bit operators versus
declarative _.includes
![Page 27: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/27.jpg)
LINKS
• Human JavaScript http://read.humanjavascript.com/
• LoDash et al. http://lodash.com
• 10 Javascript Utility Functions That You Should… http://bit.ly/1IHH5Ba
![Page 28: presentation lodash for president - GitHub...presentation_lodash_for_president Created Date 5/17/2016 11:55:10 AM](https://reader035.vdocuments.us/reader035/viewer/2022071007/5fc4e0e8b0d47a52e60d5070/html5/thumbnails/28.jpg)
BONUS
• http://lodash.com and your web console are a poor man’s playground for testing LoDash funtions… because LoDash loads itself!