-
-
Save igor-tomov/eb279b7579a26adb4f5f59854d6664df to your computer and use it in GitHub Desktop.
Revisions
-
igor-tomov revised this gist
Nov 21, 2017 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -78,6 +78,9 @@ class IngredientStore implements Storage, Plugin { } } // -------------- below should be updated ------------- class FeatureStore implements Storage, Plugin { -
igor-tomov revised this gist
Nov 21, 2017 . 1 changed file with 55 additions and 26 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,60 +4,90 @@ enum Ingredients { CREAM, SALT, } enum Features { STIR, BREW, FRY, BOIL, } interface Plugin { name: string } interface Storage { // Specific storage should define own data structure // in most cases it might be `Array<Plugin>` private storage: any add(item: Plugin): Storage remove(name: string): Storage get(name: string): Plugin } class Ingredient implements Plugin { public count: number = 0; constructor(name: string, count: number) { this.name = name; this.count = count; } } class IngredientStore implements Storage, Plugin { static storage: Array<Ingredient>; constructor() { super(); this.name = 'Ingredient Store' this.storage = []; } add(ingredient) { this.storage.push(ingredient); } remove(name) { this.storage = this.storage.filter(ingredient => ingredient.name !== name); return this; } get(name) { const ingredient = this.storage.find(ingredient => ingredient.name === name); if (! ingredient) { throw new Error(`Ingredient ${name} isn't registered`); } return ingredient; } } class FeatureStore implements Storage, Plugin { static storage: Array<Feature>; constructor() { super(); this.name = 'Feature Store'; this.storage = []; } add(feature) { @@ -131,12 +161,11 @@ class Feature implements Plugin() { } class Recipe implements Plugin() { static INGREDIENTS_LIST: Array<string>; static REQUIRED_FEATURES: Array<string>; constructor(name: string) { this.name = name; } cook(feature, ingredients) -
igor-tomov renamed this gist
Nov 21, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
igor-tomov renamed this gist
Nov 21, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
igor-tomov renamed this gist
Nov 21, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
igor-tomov created this gist
Nov 21, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,168 @@ enum Ingredients { SUGAR, COFFE, CREAM, SALT, } enum Features { STIR, BREW, FRY, BOIL, } interface Plugin { name: '' } interface Storage { storage: [] add(item) remove(name) get(name) } class Ingredient implements Plugin() { constructor() { name: '' type: '' count: 1 } } class IngredientStore implements Storage, Plugin { constructor() { this.name = 'Ingredient Store' this.storage = [] super() } add(ingredient) { storage.push(ingredient) return storage } remove(name) { storage.remove(name) return storage } get(name) { return storage.get(name) } } class FeatureStore implements Storage, Plugin { constructor() { this.name = 'Feature Store' this.storage = [] super() } add(feature) { storage.push(feature) return storage } remove(name) { storage.remove(name) return storage } get(name) { return storage.get(name) } } class RecipeStore implements Storage, Plugin { constructor() { this.name = 'Recipe Store' this.storage = [] super() } add(recipe) { storage.push(recipe) return storage } remove(name) { storage.remove(name) return storage } get(name) { return storage.get(name) } } class USM() { constructor() { this.featureRegistry = new FeatureRegistry this.ingredientStore = new IngredientStore this.recipeStorage = new RecipeStorage } unplug(name) plug(item) addIngredient(item) addRecipe(item) cook(Recipe) printPossibleDishes() on() of() } class Feature implements Plugin() { constructor() { name: '' } perform() } class Recipe implements Plugin() { static INGREDIENTS_LIST: [] static REQUIRED_FEATURES: [] constructor() { name: '' } cook(feature, ingredients) } const UCM = new UCM const sugar = new Ingredient('sugar', 1, 'kg') const coffee = new Ingredient('coffee', 1, 'kg') UCM.addIngredient(sugar) UCM.addIngredient(coffee) const espresso = new Recipe('espresso') UCM.addRecipe(espresso) const coffeeMaker = new Feature('coffeeMaker') UCM.plug(coffeeMaker) UCM.cook('espresso')