Skip to content

Instantly share code, notes, and snippets.

@igor-tomov
Last active November 21, 2017 09:39
Show Gist options
  • Save igor-tomov/eb279b7579a26adb4f5f59854d6664df to your computer and use it in GitHub Desktop.
Save igor-tomov/eb279b7579a26adb4f5f59854d6664df to your computer and use it in GitHub Desktop.

Revisions

  1. igor-tomov revised this gist Nov 21, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions *.ts
    Original 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 {
  2. igor-tomov revised this gist Nov 21, 2017. 1 changed file with 55 additions and 26 deletions.
    81 changes: 55 additions & 26 deletions *.ts
    Original 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: ''
    name: string
    }



    interface Storage {
    storage: []
    add(item)
    remove(name)
    get(name)
    // 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() {
    constructor() {
    name: ''
    type: ''
    count: 1


    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() {
    this.name = 'Ingredient Store'
    this.storage = []
    super()
    super();

    this.name = 'Ingredient Store'
    this.storage = [];
    }


    add(ingredient) {
    storage.push(ingredient)
    return storage
    this.storage.push(ingredient);
    }


    remove(name) {
    storage.remove(name)
    return storage
    this.storage = this.storage.filter(ingredient => ingredient.name !== name);
    return this;
    }


    get(name) {
    return storage.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() {
    this.name = 'Feature Store'
    this.storage = []
    super()
    super();

    this.name = 'Feature Store';
    this.storage = [];
    }

    add(feature) {
    @@ -131,12 +161,11 @@ class Feature implements Plugin() {
    }

    class Recipe implements Plugin() {
    static INGREDIENTS_LIST: []

    static REQUIRED_FEATURES: []
    static INGREDIENTS_LIST: Array<string>;
    static REQUIRED_FEATURES: Array<string>;

    constructor() {
    name: ''
    constructor(name: string) {
    this.name = name;
    }

    cook(feature, ingredients)
  3. igor-tomov renamed this gist Nov 21, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. igor-tomov renamed this gist Nov 21, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. igor-tomov renamed this gist Nov 21, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. igor-tomov created this gist Nov 21, 2017.
    168 changes: 168 additions & 0 deletions jsx
    Original 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')