Skip to content

Instantly share code, notes, and snippets.

@joliss
Last active December 17, 2015 13:10
Show Gist options
  • Save joliss/5615156 to your computer and use it in GitHub Desktop.
Save joliss/5615156 to your computer and use it in GitHub Desktop.
This is untested.
Em.View.reopen
classNameBindings: ['testingClass']
testingClass: (->
if Em.testing
if testingClass = this.valueBinding?._from?.match(/[\w|\d]+\.[\w|\d]+$/)?[0]
testingClass.replace('context.', '').replace('.', '__')
).property()
@joliss
Copy link
Author

joliss commented May 20, 2013

This exploits the fact that if the function returns false (or null/undefined presumably), the class will simply not be inserted. http://emberjs.com/api/classes/Ember.View.html

@joliss
Copy link
Author

joliss commented May 20, 2013

One problem is, subclasses might override classNameBindings and thereby kill the testingClass. Reopening (monkey-patching) base-classes like this is generally a bit icky, because it causes these kinds of problems.

@H1D
Copy link

H1D commented May 21, 2013

Thx, @joliss! I forgot that classNames is concatenated property =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment