-
Notifications
You must be signed in to change notification settings - Fork 56
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
Proposal for DeftJS enhancements needs review #78
Comments
I'd be very interested in this contribution. With regard to Behaviors - I don't see them as mix-ins. I would prefer to see Behaviors implemented as standalone objects that encapsulate their own controls, injections and observers. The idea is that the ViewController "has" Behaviors (composition) that can be added and removed dynamically at runtime, and do not pollute the ViewController's namespace with potentially conflicting properties or methods. |
Discussing some of the class-creation time vs. runtime instance creation time merging concerns with Brian. As Brian points out, the next thing everyone will need is support for extending Behaviors. |
In your example code you are manually initiating injection. Could you elaborate on why you are doing this? The inject preprocessor already merges |
I'm starting to think the ViewController and Behavior |
I now remember the problem with trying to do it at runtime and it was the merged inheritance. Observe, for example, lets you specify observers in parent and child classes. Since we don't want the child config to just override the parent, they have to be merged into a combined config when the extend processor is doing its work. :-/ |
Responses: (1) Behaviors: I can see some of the benefits of decoupling the Behavior from the ViewController, rather than make it a mix-in, although that actually makes it quite more complex because it doesn't just copy its "stuff" into the ViewController and then disappear. It would seem then that there should be an abstract class that implements the shared functionality of a ViewController and a Behavior. The only difference is that the ViewController is tied to the view, whereas the Behavior is tied to the ViewController. I suppose if it were abstracted properly, perhaps Behavior could be extended just as ViewController can be. (2) Injection: I presume you are asking only about manual injection of parent class injectors in the mergeClass method. I must have made a mistake in that, and should remove the manual injection there. However, since mergeBehaviors takes place in the constructor, I would have to manually inject there. That is, unless Behaviors is implemented as described above. Takeaway: Personally, although I can see the benefits of making Behavior decoupled, I don't have the time to implement it. It would require broader familiarity of the Deft codebase than I have, as I tried to narrow the scope of the code above to just changing the ViewController class. Let me know if/how you would like me to proceed with the mix-in approach. Thanks. |
If I follow what John is saying, I do assume there would have to be a base Behavior class that these would extend. To add the to a VC, I imagine it would either look like:
or
If either of those is on target, I'm not sure which would be better. I could see using aliases to keep it in line with how inject works. On the other hand, it would be an extra configuration step and I'm not sure there's much benefit to aliasing behaviors... |
Hi Brian - That's how I declare behaviors it my app. I did not implement alias resolution for it. Also as apparent from the code above, I mix-in behaviors in the constructor. That lets me decide whether to include a behavior at run-time, which gives me more flexibility. |
Again, the only issue with processing the behaviors at runtime and not at extends time means behaviors defined in a subclass will nullify any defined in a superclass and replace them. |
I'm starting to see that it would be okay as you say: to process behaviors when the class is extended. I'm looking at my own code at why I thought I wanted them at runtime, and the it really was just a side-effect of not giving the behaviors their own init method. If we did that (through making them encapsulated), it should be fine. |
This message is mainly for John...
I'd like to enhance DeftJS to do the following:
Below is basically what the code changes to Deft.mvc.ViewController look like. Please let me know what you think. Is this the right approach, or do you recommend something different? Will you accept a pull request if I go with this?
One note is that I took a different approach to merging controls than is already done with observers. That is, although observers are merged at class definition time, I chose to merge controls at class creation time. I made that decision, because in my own application, I find this to be more useful to be able to set/customize controls in the constructor.
Thanks.
The text was updated successfully, but these errors were encountered: