tschneidereit / SwiftSuspenders

NOTE: Find the offical repo at http://github.com/robotlegs/swiftsuspenders
https://github.com/robotlegs/swiftsuspenders
MIT License
280 stars 89 forks source link

PostConstruct generalisation #49

Closed specialunderwear closed 12 years ago

specialunderwear commented 13 years ago

Hi implemented a generalisation of the postconstruct meta tag. Currently it can only be used on methods. I adapted it to also work for function objects. This opens up the following use case:

    [Inject]
    [PostConstruct]
    public var initialize:Function;

Which means you can map and inject a postconstruct handler, before it is executed.

specialunderwear commented 12 years ago

Hi are you going to review the patch?

tschneidereit commented 12 years ago

Thanks for the pull request and sorry for making you wait this long.

That's a very clever idea you have here - it took me quite some time to really understand where the real value of it is. I have to think about this some more and see how to properly integrate it into Swiftsuspenders 2, though. That last part most likely means that I'll not take your pull request but implement the idea in a possibly slightly different way. In that case, I would of course add you to the contributors file, or, if you'd prefer that, I can also get back to you and give you directions to make the required changes yourself.

specialunderwear commented 12 years ago

Hi, I'll gladly modify the patch to apply to swiftsuspenders 2, including any modifications you require. Please note that effectively, there are only 2 lines of code changed. The rest is all unit tests to demonstrate the use cases, which these very minor changes open up.

tschneidereit commented 12 years ago

Ok, thanks for the offer. I will let you know once I'm ready to work with you on that. Might be a couple weeks, though.

darscan commented 12 years ago

Has this been explored further?

tschneidereit commented 12 years ago

Yes, a bit. I will definitely include it in 2.0.

specialunderwear commented 12 years ago

Yay!

tschneidereit commented 12 years ago

So I finally got around to implementing this. Turned out to be pretty easy after all. I will have to do some performance analysis later on, but the impact shouldn't be major at all.

darscan commented 12 years ago

Sounds like a fun feature to blog about.

tschneidereit commented 12 years ago

Which I absolutely plan on doing, yes. I hope to do a series of posts that I can then turn into some sort of cookbook/ specual features section for the docs.

specialunderwear commented 12 years ago

If you liked that, maybe you want to check out: https://github.com/specialunderwear/as3-mixin which elaborates on the concept.

specialunderwear commented 12 years ago

Hmm I think something is missing in the tests. The point of the original unit tests, is that the injected postconstruct handler, acts like a method and has access to 'this' which is properly bound to the unjection target. Somehow that got lost in translation. When i get access to my computer, I'll Try to add it to your current test suite.

tschneidereit commented 12 years ago

See the last test: that verifies that the method is executed in the injectee's scope.

And thanks for the link to your mixin project. Very interesting indeed.

specialunderwear commented 12 years ago

You're right, sorry.