Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #841: bring back the extended hook #1960

Conversation

michaelficarra
Copy link
Collaborator

I say we go for it.

@jashkenas
Copy link
Owner

Thanks for the implementation -- we should definitely decide this one way or another before 1.2.1, but let's not merge this quite yet...

@michaelficarra
Copy link
Collaborator Author

Of course.

@michaelficarra
Copy link
Collaborator Author

@jashkenas: we're going to need another release soon (a new minor version), so how are we going to handle this? I say we merge it.

@danielribeiro
Copy link

+1

@goomtrex
Copy link

Minus one.

@keithnorm
Copy link

+1

1 similar comment
@nathansobo
Copy link

+1

@CodeMonkeySteve
Copy link

+10

@michaelficarra michaelficarra mentioned this pull request Apr 8, 2012
@jashkenas
Copy link
Owner

I had a nice long chat with @wycats about Ember's need for the extended hook, and I'm afraid I persuaded myself that we shouldn't do it.

There are good arguments for running extended before the class body is defined -- to make functions that it adds to the class object available within the class body; and there are good arguments for running extended after the class body is defined -- in case it wants to iterate through the prototype and enhance properties of a certain kind. Given that both are valid use cases, I don't think we should do either. Instead:

class A extends B
  B.extended(this)
  ... class body ...


class A extends B
  ... class body ...
  B.extended(this)

... or many other possible uses of dynamic hooks during class definition. Hard-coding a single extended hook would add magic to our class semantics (above and beyond JS) while hiding the much more powerful abilities of executable class bodies and JavaScript exposed prototypes. I don't think it's worth it.

@jashkenas jashkenas closed this Apr 10, 2012
@michaelficarra
Copy link
Collaborator Author

I can accept that reasoning. Thanks for looking into this.

@wycats
Copy link

wycats commented Apr 10, 2012

We also discussed the possibility of adding in a compiler hook so that it would be easier to maintain an Ember variant of CoffeeScript without forking the entire project.

Thoughts?

@michaelficarra
Copy link
Collaborator Author

@wycats: Like #1968? Be sure to read #1023 as well.

@grayrest
Copy link
Contributor

My extended use case would also work with a compiler hook.

@jashkenas
Copy link
Owner

I think in this case you'd just want a finer-grained breakdown of the "class" compilation function in nodes.coffee ... then you'd have (ideally) a single function to override. It's not an "events" thing, I don't think.

@wycats
Copy link

wycats commented Apr 10, 2012

I'd optimally want to be able to subclass the compiler and override some hooks, rather than try to do something with events.

@collin
Copy link

collin commented Apr 11, 2012

I'm doing some terribly awful things to coffeescript and "classes" https://github.com/collin/pathology

I would also like to be able to flip some switches and override the 'class' part of the compiler.

But I think it's potentially a recipe for sadness. Say if I want to use two libraries that need to compiler overridden in different incompatible ways.

What are the use cases for class extension hooks other than wrapping around the class body? I can see re-opening a class, but not much else.

@nathansobo
Copy link

What about beforeExtended and afterExtended to cover the two cases discussed above? As it stands users of my library will have to call @extended manually at the top of the class body, which isn't horrible but could be prettier.

@collin
Copy link

collin commented Apr 11, 2012

I think a better hook would be executeClassBody, which would be passed in a function to be executed as the class body.

This would allow for extensions that hook before extension, after extension and allow for re-opening of classes.

@jashkenas you mention other scenarios that you don't want to trample on, I'd like to know what those are in case I'm completely missing the boat on this.

@lancejpollard
Copy link

+10

Adding a compiler hook would be ideal so as to avoid creating a custom fork of coffeescript that does something like: https://gist.github.com/2365817.

@d4tocchini
Copy link

Thanks @viatropos.

The extended hook was not enough for Ember compatibility. I added defineProperty, defineStaticProperty & extend hooks. Results in many atomic ember.reopen & ember.reopenClass, but it does the trick without screwing up lexographic ordering of methods executed in class bodies. Bottom-line, CoffeeScript & Ember should get along.

A more generalized mechanism for extending the compiler would be awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.