Created
August 19, 2018 14:55
-
-
Save RayLuxembourg/4005030bac6af6efc77cd67200592fc8 to your computer and use it in GitHub Desktop.
example.repeatable-code.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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