Closed aljimenez closed 10 years ago
CLA is valid!
IMHO we need to do extensive performance testing to determine any possible impact of this. And i'm not a big fan of having to declare the dependencies in another file (defaults.json), seems to me confusing and error prone.
This pull request does not change the execution flow for any existing application. It only adds a new feature, which is to allow a mojit controller to be specified as a function with a prototype. This has no performance impact, since the execution flow remains the same. The only thing that changes is that instead of mojito using Y.mojito.util.heir to create the controller object (see heir), the controller object is created directly from the controller function. This means that we don't have to create a new function every time, which obviously wouldn't degrade performance or memory usage. Specifying the dependency somehow is necessary only if using lazyMojits, there is no way around this, and shouldn't be a huge issue for users since extending the modules of another mojit should be rare. In fact without the pull request mojits extending another mojit's modules would have to specify the dependency through YUI().applyConfig (see ShakerPipelineFrame), in case lazyMojits is on. Specifying the dependencies in default.json is probably the cleanest most intuitive way (and probably good practice anyways since in general mojits are self contained, so its a good idea to mention that it depends on another mojit in its configuration).
This PR is misleading, it is not extending mojits, it is extending individual modules within a mojit, and that's supported today as far as I can tell, by relying on the YUI module definition, I wonder why are you trying to mix the concepts of a mojit and modules in this PR.
Thats right, you can extend any YUI module of another mojit, including controllers, binders, models... This pull request enhances 3 things:
In the latest commit, Y.mojito.util.heir accepts functions in addition to object literals. This allows controllers/binders/models to be defined as functions, which can be useful when extending other YUI modules. The commit also adds Y.mojito.util.extend, a wrapper around Y.extend, in order to accept either functions or object literals as arguments.
need some time to go over this tomorrow.
Thanks Caridy, let me know if I should clarify anything.
@caridy can you review this when you get a chance; we have some application code that depend on this pull request. Thanks.
@aljimenez let's have a chat tomorrow about this PR, I have few specific questions and some suggestions, but this is a very complex PR, hard to make sense of all pieces.
@caridy sounds good. The pull request did get a bit complicated due to some refactoring and some other fixes that I slipped in, somewhat unrelated to the original pull request. I'll make sure to separate the distinct features in different branches in the future, thanks.
ok, I will not hold back on this: +0.9
Thanks @caridy I will merge this soon, and I'll keep in mind your suggestions.
This pull request allows mojits to easily extend YUI modules of other mojits. For example:
mojits/Vehicle/controller.server.js
mojits/Motorcycle/controller.server.js
In this example, the Motorcycle mojit extends the Vehicle mojit, which extends the Y.Base class (extending Y.Base is not a requirement, the example just illustrates multiple level of extensions). Notice that the controllers can be defined as a function; this allows mojits to extend using Y.extend, which ensures that the prototype chain is maintained regardless of how many levels of extensions. Also notice that the Motorcycle controller does not have to re-specify the 'mojito-params-addon' requirement; it just has to specify the Vehicle controller requirement, and its addon will automatically include any addon required by Vehicle controller.
To ensure that mojit dependencies work with resourceStore > lazyMojits on, mojits depending on other mojits should specify their dependencies in defaults.json:
mojits/Motorcycle/defaults.json