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

Growing features


What we've done so far is basically useless. But, from now on, we will start to add features and make it capable of fitting in practical needs, including the capability of synchronizing multiple data items with multiple clients, and merging conflicts.

Synchronizing multiple items

Ideally, the data we need to synchronize will have a lot of items contained. Directly changing the type of data to an array would work if there were only very limited number of these items.

Simply replacing data type with an array

Now let's change the type of the data property of DataStore and DataSyncingInfo interfaces to string[]. With the help of TypeScript, you will get errors for unmatched types this change would cause. Fix them by annotating the correct types.

But obviously, this is far from an efficient solution.

Server-centered synchronization

If the data store contains a lot of data, the ideal approach would be only updating items that are not up-to-date.

For example, we can create a timestamp...