-
Notifications
You must be signed in to change notification settings - Fork 12
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
AMD #6
Comments
One important note about the proposed approach: no AMD will be available outside of our core code. This means that plugins, or anything that is to be loaded on demand, will not be coded on AMD. The reasoning behind this is that we cannot require any AMD library to be able to run the build version of CKEditor. Therefore, on demand code should also not require AMD libraries. There would be a solution for this. We could provide CKEditor specific AMD support in our API, namely |
I agree will all this. We definitely shouldn't require or ship with an AMD library. However:
|
Hmm.. why not UMD? |
I don't know UMD, so I'm not commenting it now. But a general advice for us should be that only well defined, and widely used libraries/concepts should be adopted. Architecture that we're now designing will be used by us for next 10+ years, so last season's solutions are a risk. |
We continued with @fredck a discussion about a case when developer wants to load plugins on demand (possibly from locations outside CKEditor directory). Currently CKEditor's core handles loading plugins. External plugins can be registered using Since we are thinking about using AMD for the core of v5 we could also consider using AMD in case of plugins. However, that would mean that in prod env RequireJS or other library is a new requirement. This is 16kb that would never be used by developers that have precisely configured builds, so we should avoid it. Additionally, a project may already use RequireJS and then code would be duplicated. Possible solutions:
Sadly, it seems that if we want to make use of RequireJS and be compatible with it we must be very careful or there will be many constraints. This raises a question whether it's worth trying. Whether the first solutions isn't better. In any case, if a developer will want a highly optimised page on which CKEditor is compiled with other libraries, (s)he can use CKEditor's builder to create a single-file package. We should just make sure that there's also a possibility to build a My KISS sense tells me that solution 1 with no code for dynamic JS loading at all (so no config.js and styles.js - want to extract them? include them manually - no more magic) and a clever builder as the one described in our email thread will do best (so the requirements are kept outside plugins in separate file and builder is used to create a loader file which is used in dev env to load all this). I'm even thinking whether stylesheets should be loaded automatically, because... why? It always make problems when you want to concatenate your assets. |
I'd like to add that I like the idea of using AMD (also) because it is a kind of dependency injection, and DI is great to make tests far more separated. |
True. AMD will allow us to control DI and we planed to solve this issue anyway. So AMD used on the entire code base is not only for the beauty. |
It struck me on yesterday's CopenhagenJS - could we use ES6 modules? We will need to use some converter for them, because they are not yet widely supported, but I'm sure there are some. The good thing about ES6 modules is that one day we won't need any additional loader and for guys that work on limited environments (for instance Chrome/FF only) this day will come pretty soon. There are of course many details why ES6 modules might not work for us, but I think that we should at least make a research about them. |
Using ES6 modules would require us to compile our code to be able to run it. Especially because there is still no support for it. I'm not sure it is worth the effort and still the whole modules thing is under work, so we can expect changes on it in the future. It would be a very experimental way to go. Additionally, we would require people to understand things that they still don't understand. Our code would be really made for us only. For instance, as compilation would be needed, we could even think about going ahead with many of the ES6 features by using tools like Traceur. Still we're entering in a field of fun... and pain. Additionally, we would have totally different ways of programming: one for core and another for external stuff (plugins). AMD is already a standard and well accepted pattern. It's proving to be a good way to solve our problem. Hopefully we found a nice way to use it, so there is no additional benefit on complicating the present with ES6 modules aiming for a brighter future. |
After a bit of thinking, I don't like ES6 modules. I was thinking only about our code, but there will be 3rd party plugins and we can't expect from their developers too much. AMD is better in this case. As for the rest of ES6 features, AFAICR some of them are already stable in terms of specification. But I agree with you that by taking too much of it we would make our code harder to read for developers that don't follow standards so closely. On the other hand, there are some very tempting parts like block scoping, desctructuring assignments or classes which are simple to understand (unlike generators for which is too early IMO) but affects the way how you code significantly. In fact, if we started using ES6 classes we would be sure that they are always consistently created and used - veeery tempting. And we would make sure that our code looks fresh for a long time - we need to remember v5's life time. The bottom line is, however, what's the performance of Traceur, how stable it is and what's the performance and size of code it generates. I'm afraid that if we start with it and will be dissapointed it will be very quickly hard to step back. |
Another reason for not going ES6 way - documentation. We don't have a tool that's able to comprehend ES6 code. Another reason - linting. Another reason - code style checking. So... nope :D. |
BTW. Final syntax of ES6 modules has been defined - http://www.2ality.com/2014/09/es6-modules-final.html |
Didn't fully read yet, but it touches a topic which worried me as well - http://orizens.com/wp/topics/a-journey-from-require-js-to-browserify/ |
Just one of the issues pointed by the article may eventually touch us, which is the potential size of the require list on the module definition. That is generally considered one of the AMD weaknesses, but this is just theory, because if you really have those dependencies you will have lots of require() calls inside your code anyway, in the CommonJS style. So it may look ugly, but it's not anything more than that. I'm sure that all options have weak points, so we have to pick one. I would stick with AMD, RequireJS and the way proposed in the "amd" prototype branch. |
Our approach to AMD has been described at the following wiki page: AMD I would ask @gregpabian, @Reinmar and others to please give it a quick look and see if there is anything wrong or missing. |
When we talk about the development environment, the actual paths are:
Besides, it's
Not yet true for the prototype, but might be :) |
Ok, fixed.
Yes, the documentation must make it clear how it will look like, not simply describe the prototype. Based on the docs we gonna start the real implementation. |
I actually haven't yet check AMD at all and I didn't have time to reply to Grzesiek regarding MVC. I'll do that tomorrow. |
Note that I'm asking for review on the AMD documentation, not on the prototype code. That code may be used just to understand better what the documentation is saying. |
Just a quick comment about ES6: https://medium.com/@brianleroux/es6-modules-amd-and-commonjs-c1acefbe6fc0 Just for the record, I like AMD too :) |
Yes, the future will be wonderful! We took this in consideration, but to be able to use it (partially) we would have to have code pre-processors and we want to avoid this. So, for now we're going with RequireJS. |
A proposal for AMD in the CKEditor development code has been pushed to the amd prototype branch.
Read the README file there first, to have a general understanding about the goals of the prototype.
The text was updated successfully, but these errors were encountered: