Book Image

TypeScript Design Patterns

By : Vilic Vane
Book Image

TypeScript Design Patterns

By: Vilic Vane

Overview of this book

In programming, there are several problems that occur frequently. To solve these problems, there are various repeatable solutions that are known as design patterns. Design patterns are a great way to improve the efficiency of your programs and improve your productivity. This book is a collection of the most important patterns you need to improve your applications’ performance and your productivity. The journey starts by explaining the current challenges when designing and developing an application and how you can solve these challenges by applying the correct design pattern and best practices. Each pattern is accompanied with rich examples that demonstrate the power of patterns for a range of tasks, from building an application to code testing. We’ll introduce low-level programming concepts to help you write TypeScript code, as well as work with software architecture, best practices, and design aspects.
Table of Contents (15 chapters)
TypeScript Design Patterns
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Getting things right


So let's get out of the illusion of comparing code one character at a time and try to find an abstraction that can be applied to updating all of these data types. There are two key points of this abstraction that have already been mentioned in the previous section:

  • A change contains the information that can transform the value of an item from one to another

  • Multiple changes could be generated or applied to one data item during a single synchronization

Now, starting from changes, let's think about what happens when an update method of a client is called.

Finding abstraction

Take a closer look to the method update of client:

  • For data of the 'value' type, first we create the change, including a new value, and then update the change list to make the newly created change the only one. After that, we update the value of data item.

  • For data of the 'increment' type, we add a change including the increment in the change list; or if a change that has not be synchronized already exists...