Skip to content

Instantly share code, notes, and snippets.

@RayLuxembourg
Created August 19, 2018 14:55
Show Gist options
  • Save RayLuxembourg/4005030bac6af6efc77cd67200592fc8 to your computer and use it in GitHub Desktop.
Save RayLuxembourg/4005030bac6af6efc77cd67200592fc8 to your computer and use it in GitHub Desktop.
example.repeatable-code.ts
interface BaseProduct {
name: string;
id: number;
price: number;
}
interface ProductsList {
top: BaseProduct[];
bottom: BaseProduct[];
}
class SliderX {
data: ProductsList
next(): void { };
getStandartProduct(): ProductsList {
return { top: [], bottom: [] }
}
init() {
this.data = this.getStandartProduct();
// .... rest of the logic
}
}
class SliderY {
data: ProductsList
next(): void { }
init() {
const baseProduct = this.getBaseProduct();
const bottom = this.getRecommendedProducts(baseProduct.id);
this.data = {
top: [baseProduct],
bottom
}
// .... rest of the logic
}
getBaseProduct(): BaseProduct {
return {
name: 'someName',
id: 1,
price: 33
}
}
getRecommendedProducts(baseProductId: number): BaseProduct[] {
// get Recommended products from server using the baseProduct
return [{
name: 'someName',
id: 1,
price: 33
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment