Skip to content

Instantly share code, notes, and snippets.

@zackbloom
Created August 29, 2013 01:45
Show Gist options
  • Select an option

  • Save zackbloom/6373430 to your computer and use it in GitHub Desktop.

Select an option

Save zackbloom/6373430 to your computer and use it in GitHub Desktop.
mixins = {}
registerMixin = (name, mixin) -> mixins[name] = mixin
defaultMixins = ['event-janitor']
registerMixin 'event-janitor', EventJanitor
registerMixin 'remember-me', RememberMe
MixMaster = (mixins...) ->
out = _.clone defaultMixins
for mixin in mixins
if mixin[0] is '+'
out = _.union out, mixin.substring(1)
else
out = _.without out, mixin.substring(1)
Mixen out
# You can now make classes like this:
class MyView extends MixMaster('+remember-me', '-event-janitor')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment