Skip to content

Instantly share code, notes, and snippets.

View nthx's full-sized avatar

Tomasz Nazar nthx

View GitHub Profile
@nthx
nthx / hashmal_mixins.coffee
Created May 16, 2012 23:24
hashmal modified Mixin
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
@nthx
nthx / ObjectHelper.coffee
Created May 16, 2012 23:19
ObjectHelper
class ObjectHelper
@addRole: (base, role) =>
if not role::augment?
throw "RoleMustHave.augment()"
role::augment(base)
_.bindAll(base)
@nthx
nthx / Mixin short example.coffee
Created May 16, 2012 23:16
Mixin short example
class Nothing
constructor: (@name="nothing") ->
class Presenter extends Mixin
presentYourself: =>
"My name is #{@name}"
something = new Nothing()
ObjectHelper.addRole(something, Presenter)
@nthx
nthx / Mixin long example.coffee
Created May 16, 2012 23:04
Mixin long example
class Nothing
constructor: (@name="nothing") ->
doSomething: =>
"I cannot do anything"
class Presenter extends Mixin
presentYourself: =>
"My name is #{@name}"
class InviteFriendsUsecase
execute:
bind('click', player.inviteFriends())
class model.Player
inviteFriends: =>
@nthx
nthx / gist:2028946
Created March 13, 2012 14:01
god_systems_god_1
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)
@nthx
nthx / gist:2028882
Created March 13, 2012 13:52
god_systems_usecase_2
#async/callbacks ignored for clarity of example
class WatchItemUsecase
constructor: (@ebay, @seller) ->
execute: (item) =>
try
@ebay.seller_wants_to_watch_item(@seller, item)
@nthx
nthx / gist:2028860
Created March 13, 2012 13:47
god_systems_usecase_1
#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')
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)