This file contains 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
require 'thor' | |
require 'faker' | |
class HeroCLI < Thor | |
end | |
HeroCLI.start(ARGV) |
This file contains 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
class HeroCLI < Thor | |
desc "superhero", "Display a superhero" | |
def superhero | |
my_hero = "#{Faker::Superhero.name} #{Faker::Superhero.suffix}" | |
puts my_hero | |
end | |
end |
This file contains 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
class HeroCLI < Thor | |
desc "superhero WEAKNESS", "Display a superhero and its weakness." | |
def superhero(weakness) | |
my_hero = "#{Faker::Superhero.name} #{Faker::Superhero.suffix}" | |
puts "#{my_hero} has been foiled again by #{weakness}!" | |
end | |
end |
This file contains 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
class HeroCLI < Thor | |
desc "superhero [WEAKNESS]", "Display a superhero and its weakness." | |
def superhero(weakness='bad puns') | |
my_hero = "#{Faker::Superhero.name} #{Faker::Superhero.suffix}" | |
puts "#{my_hero} has been foiled again by #{weakness}!" | |
end | |
end |
This file contains 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
class HeroCLI < Thor | |
... | |
desc "assemble TEAM", "Displays a TEAM of superheroes." | |
option :size, :type => :numeric, :required => true, :desc => "How many superheroes to assemble" | |
def assemble(team) | |
puts "***#{team} Assemble***" | |
options[:size].times do | |
puts "#{Faker::Superhero.name} #{Faker::Superhero.suffix}!" |
This file contains 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
// implementing event emitter pattern | |
class EventEmitter { | |
constructor() { | |
this.events = {} // initialize with empty events object | |
} | |
addEventListener(eventLabel, callback) { // create a new key for our event with the eventLabel | |
if (!this.events[eventLabel]) | |
this.events[eventLabel] = [] | |
This file contains 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
class FluxModel extends EventEmitter { | |
constructor() { | |
super() // initialize the EventEmitter | |
this.time = new Date() // set the current time | |
this.isNighttime = this.getNighttime() // check if it is nighttime | |
setInterval(this.updateTime.bind(this), 60000) // update our model's state every minute | |
} | |
updateTime() { | |
let previousIsNighttimeState = this.isNighttime // save the PREVIOUS STATE of our application |
This file contains 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
class FluxController extends EventEmitter { | |
constructor(model, view) { | |
super() | |
this.model = model | |
this.view = view | |
// add event listeners for changes to our model state | |
model.addEventListener('daytime', () => this.changeViewToDaytime()) | |
model.addEventListener('nighttime', () => this.changeViewToNighttime()) |
This file contains 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
class FluxView { | |
constructor(components) { | |
this.body = components["body"] | |
} | |
} |
This file contains 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
document.addEventListener('DOMContentLoaded', () => { | |
const body = document.querySelector('body') | |
const fluxModel = new FluxModel() | |
const fluxView = new FluxView({ body: body }) | |
const fluxController = new FluxController(fluxModel, fluxView) | |
}) |
OlderNewer