Patterns for TypeScript
npm install @xapp/patternsCommon TypeScript design patterns and data structures.
Extend the AbstractBuilder to leverage your own builder pattern.
``typescript
import { AbstractBuilder } from "@xapp/patterns";
export interface MyObject {
foo: string;
}
export class MyBuilder extends AbstractBuilder
private foo: string = "defaultFooValue";
public withFoo(foo: string): MyBuilder {
return this;
}
public build(): MyObject {
const { foo } = this;
return {
foo,
};
}
}
``
- Example - Unit Test
- Example - Real World
- Builder Pattern - Wikipedia
A graph is an abstract data type with vertices and edges that make the connections between them.
- Example - Unit Test
- Graph (abstract data type) - Wikipedia>)
A tree is a data structure with a root and nodes that then expand from the root.