Lo-Dash Essentials

Book description

Implement fast, lean, and readable code effectively with Lo-Dash

In Detail

Lo-Dash Essentials walks you through the Lo-Dash utility library, which promises consistency and performance in JavaScript development. This book looks into the most common functions and the various contexts in which they're used. You'll first start with object types and their properties, then you'll dive into larger development patterns, such as MapReduce, and how to chain functionality together. Following this, you'll learn how to make suitable builds for various environments, and discover how high-level patterns complement one another and how they lead to reusable building blocks for applications. Finally, you will gain some practical exposure to Lo-Dash by working alongside other libraries, and learn some useful techniques for improving performance.

What You Will Learn

  • Analyze the difference between arrays, collections, and objects and look at how Lo-Dash treats them

  • Understand the subtle differences between iterating over arrays and objects, along with object-creation patterns used with Lo-Dash

  • Exploit and work with Lo-Dash functional tools, such as partially applying arguments, and composing higher-order functions

  • Explore the various approaches of MapReduce and their relationships with other Lo-Dash functions

  • Build your own Lo-Dash application for various environments

  • Compare Lo-Dash with other libraries and decide where Lo-Dash is a good fit

  • Understand the key Lo-Dash design principles and utilize this knowledge to deliver performant user interfaces

  • Table of contents

    1. Lo-Dash Essentials
      1. Table of Contents
      2. Lo-Dash Essentials
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Working with Arrays and Collections
        1. The difference between arrays and collections
        2. Iterating over collections
        3. Sorting data
          1. Using sortBy()
          2. Maintaining the sort order
        4. Searching for data
          1. Filtering collections
          2. Finding items in collections
        5. Slicing collections into smaller pieces
          1. First and last collection portions
          2. Splitting collections into chunks
          3. Building unique arrays
        6. Transforming collections
          1. Grouping collection items
          2. Counting collection items
          3. Flattening and compacting
          4. Validating some or all items
          5. Unions, intersections, and differences
        7. Summary
      9. 2. Working with Objects
        1. Determining an object type
          1. Type coercion
          2. Managing function arguments
          3. Arithmetic
          4. Callable objects
        2. Assigning and accessing properties
          1. Extending objects
          2. Defaults for new objects
          3. Finding keys and values
        3. Iterating over objects
          1. Basic For Each
          2. Including inherited properties
          3. Keys and values
        4. Calling methods
          1. Getting results
          2. Finding methods
        5. Transforming objects
          1. Using pairs
          2. Picking and omitting properties
          3. Inverting keys and values
        6. Creating and cloning objects
          1. Creating objects
          2. Cloning objects
        7. Summary
      10. 3. Working with Functions
        1. Binding function contexts
          1. Changing the this keyword
          2. Binding methods
          3. Dynamic methods
        2. Decorating functions
          1. Partials
          2. Function decorators
        3. Function constraints
          1. Limiting call counts
          2. Caching values
        4. Timed execution
          1. Delaying function calls
          2. Deferring function calls
          3. Throttling function calls
          4. Debouncing function calls
        5. Composing and currying functions
          1. Composing functions
          2. Currying functions
        6. Summary
      11. 4. Transformations Using Map/Reduce
        1. Plucking values
        2. Mapping collections
          1. Including and excluding properties
          2. Performing calculations
          3. Calling functions
          4. Filtering and mapping
        3. Mapping objects
          1. Working with keys
          2. Calling methods
          3. Mapping key-value pairs
        4. Reducing collections
          1. Summing values
          2. Filtering and reducing
          3. Min, max, and average operations
        5. Reducing objects
          1. Reducing keys
          2. Object accumulators
        6. Binding contexts
        7. Map/reduce patterns
          1. Generic callback functions
          2. Map/reduce chains
        8. Summary
      12. 5. Assembling Chains
        1. Creating Lo-Dash wrappers
          1. Chained calls
          2. Wrapping values
          3. Explicit and implicit chaining
        2. Building filters
          1. Multiple filter() calls
          2. Combining filter() with where()
          3. Dropping and taking collection items
          4. Rejecting items
          5. Using initial() and rest()
        3. Testing truth conditions
          1. Testing if a collection contains an item
          2. Everything or anything is true
        4. Counting items
          1. Using length and size()
          2. Grouping using countBy()
          3. Reducing collections
        5. Transformations
          1. Building groups, unions, and unique values
          2. Plucking values
          3. Creating arrays using without()
          4. Finding the min and max values
          5. Finding the index
          6. Using difference() and xor()
        6. Intermediary results
          1. Tapping into chains
          2. Injecting values
        7. Keys and values
          1. Filtered keys and values
          2. Omitting and picking properties
        8. Returning wrappers
        9. Summary
      13. 6. Application Building Blocks
        1. Generic functions
          1. Specific functions
          2. Generic function arguments
          3. Using partials
          4. Generic callbacks
        2. Generic wrappers and chains
          1. Generic filters
          2. Returning chains
        3. Composing functions
          1. Composing generic functions
          2. Composing callbacks
          3. Composing chains
          4. Method composition
        4. Creating mixins
          1. Creating an average() function
          2. Creating a distance() function
        5. Summary
      14. 7. Using Lo-Dash with Other Libraries
        1. Modules
          1. Organizing your code with modules
          2. Requiring Lo-Dash
          3. Working with Lo-Dash AMD modules
        2. jQuery
          1. Challenges faced by Lo-Dash
          2. Challenges faced by jQuery
          3. Using jQuery instances as collections
          4. Binding functions
          5. Working with jQuery deferred instances
        3. Backbone
          1. Replacing Underscore.js
          2. Full-featured Lo-Dash and Backbone
          3. Enhancing collections and models
        4. Node.js
          1. Installing the Lo-Dash package
          2. Creating a simple command
          3. Custom Lo-Dash builds
        5. Summary
      15. 8. Internal Design and Performance
        1. Design principles
          1. Function compilation to base functions
          2. Optimizing for the common case
          3. Loops are simple
          4. Callbacks and function binding
        2. Improving performance
          1. Changing the operation order
          2. Sorting and indexing collections
          3. Bound and unbound callbacks
        3. Lazy evaluation
        4. Caching things
        5. Summary
      16. Index

    Product information

    • Title: Lo-Dash Essentials
    • Author(s): Adam Boduch
    • Release date: January 2015
    • Publisher(s): Packt Publishing
    • ISBN: 9781784398330