Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Immutable JavaScript Array & Object Patterns

Purpose

Prerequisites

Patterns

Pattern Description What problems can this pattern solve? What solution does this pattern describe?
Building a Complex Object Once Pattern for building a complex object with a clear shape - Avoid mutating object fields
- Avoid unnecessary state
- Avoid confusing object shapes
- Use operators for computing shallow fields (e.g. ternary, nullish coalescing, optional chaining)
- Use functions for computing nested fields
- Return complete object at creation
Building an Array with Optional Items Pattern for building an array with optional items - Avoid mutating array methods
- Avoid unnecessary state
- Avoid confusing array contents
- Define an array containing all potential items
- For each item, indicate whether it should be included
- Idea 1) Add a field to indicate if it should be included
- Idea 2) Include the item or null ([myVal1, condition ? 'myVa2' : null])
- Return filtered/mapped array
Declaratively Transforming an Array Pattern for transforming an array declaratively - Avoid mutating array methods
- Avoid unnecessary state
- Avoid combined transformation and result creation logic
- Define a transformation object (e.g. { myField: myNewField() })
- Use map/flatMap using the transformation object

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages