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
Swappable Mixins in CoffeeScript | |
# ================================ | |
# Many thanks to Hashmal, who wrote this to start. | |
# https://gist.github.com/803816/aceed8fc57188c3a19ce2eccdb25acb64f2be94e | |
class Mixin | |
augment: (t) -> | |
(t[n] = m unless n == 'augment' or !this[n].prototype?) for n, m of this | |
t.setup() | |
eject: (mixin) -> | |
(delete this[n] if m in (p for o, p of mixin::)) for n, m of this |
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
class ObjectHelper | |
@addRole: (base, role) => | |
if not role::augment? | |
throw "RoleMustHave.augment()" | |
role::augment(base) | |
_.bindAll(base) |
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
class Nothing | |
constructor: (@name="nothing") -> | |
class Presenter extends Mixin | |
presentYourself: => | |
"My name is #{@name}" | |
something = new Nothing() | |
ObjectHelper.addRole(something, Presenter) |
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
class Nothing | |
constructor: (@name="nothing") -> | |
doSomething: => | |
"I cannot do anything" | |
class Presenter extends Mixin | |
presentYourself: => | |
"My name is #{@name}" |
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
aaa |
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
class InviteFriendsUsecase | |
execute: | |
bind('click', player.inviteFriends()) | |
class model.Player | |
inviteFriends: => |
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
class Ebay | |
constructor: -> | |
#I'm yet to decide if static vs dynamic roles' assignment | |
#is better. It doesn't matter so much for now | |
#extend(@, EbayCanBeWatchedRole) | |
#extend(@, SellersCanListRole) | |
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
#async/callbacks ignored for clarity of example | |
class WatchItemUsecase | |
constructor: (@ebay, @seller) -> | |
execute: (item) => | |
try | |
@ebay.seller_wants_to_watch_item(@seller, item) |
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
#async/callbacks ignored for clarity of example | |
class ListItemUsecase | |
constructor: (@ebay, @seller) -> | |
execute: (listing_definition) => | |
answer = @ebay.list_items(@seller, @ebay) | |
if answer.listing_is_valid() | |
alert('ok - item was scheduled for listing') |
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
describe "Any Game", -> | |
describe "GameResults", -> | |
describe "When any application starts", -> | |
afterEach -> | |
$("#gameScreen").remove() | |
it "shooter should show game results when game ends", -> | |
[engine, services] = runEngineApp('shooter', test.shooter.ServerResponses) |