You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JS entry point for apps, make it possible to load resources async #17169
The fact that currently app's JS code can do "whatever they want" makes it impossible to load resources asynchronously like translations or mimetypes. This leads to workarounds like having a generated JS file that can be loaded with addScript() instead of on-demand / with ajax.
One solution to think about would be to provide entry point hooks for apps.
An app's JS code should then register itself: OC.App.register("My app", myAppClass).
The myAppClass would then have a method init() that will be called asynchronously after all async resources are ready.
Note that this is not only about the currently visible app. Multiple apps can register their JS code at the same time, like file viewers (FileActions) when the file action is visible, etc.
So it's a matter of providing a single entry point for apps.
Additionally there is also the complexity of having apps using APIs of other apps.
For example the PDF viewer app uses the FileActions API from the files app to register its action.
The files_sharing app extends the FileList class provided by the files app, to be able to display a list of shared files.
It is more about using APIs that require async loading of stuff, but using them in a non-async manner.
So let's say if we do @rullzer's mimetype change but load JSON asynchronously, but provide a method OC.Mimetypes.getIcon() without callback or promise, then if an app calls OC.Mimetypes.getIcon() too early, they won't get any result. However if they call it inside the init() method (which we call afterwards), they'd get results.
So as long as old apps don't use such APIs, they should be fine.
This means as soon as we want to introduce such APIs that require async load, the init() mechanism needs to be ready too.
This will also be needed to be able to get rid of the ".js" translation files eventually.
Apart from translation, I can't think of any other API that would affect old apps right now.
I'm with @Raydiation. Custom sauce is going to increase the complexity and the maintenance level of the project. Educating devs into using a loader is going to have long term benefits for a relatively small price to pay in development time.
Another worry I have is whether an app's webpack modules would be able to "extend" (in the JS subclass way) classes from the core module. This would require the app bundle to know about the core bundle.
Activity
[-]App JS code must run asynchronously[/-][+]JS entry point for apps, make it possible to load resources async[/+]PVince81 commentedon Jun 25, 2015
Note: the files app and other core apps already use a similar mechanism with
OC.Plugins.register().For example https://github.com/owncloud/core/blob/master/apps/files/js/favoritesplugin.js#L115
Additionally there is also the complexity of having apps using APIs of other apps.
For example the PDF viewer app uses the FileActions API from the files app to register its action.
The files_sharing app extends the FileList class provided by the files app, to be able to display a list of shared files.
So this isn't only about a single app.
DeepDiver1975 commentedon Jun 25, 2015
Can we have this for 8.2?
PVince81 commentedon Jun 25, 2015
Yes, we can have the discussion during 8.2.
Regardless of the solution, it will be incompatible with any existing apps. So the hardest part would be to find a way to provide a fallback.
DeepDiver1975 commentedon Jun 25, 2015
From my understanding it more of that kind:
In case an app registers a init callback we call it - if not we simply don't?
Non of the existing apps as of today has such an init mechanism - and if it should continue to work - right?
PVince81 commentedon Jun 25, 2015
Yes.
It is more about using APIs that require async loading of stuff, but using them in a non-async manner.
So let's say if we do @rullzer's mimetype change but load JSON asynchronously, but provide a method
OC.Mimetypes.getIcon()without callback or promise, then if an app callsOC.Mimetypes.getIcon()too early, they won't get any result. However if they call it inside the init() method (which we call afterwards), they'd get results.So as long as old apps don't use such APIs, they should be fine.
This means as soon as we want to introduce such APIs that require async load, the init() mechanism needs to be ready too.
This will also be needed to be able to get rid of the ".js" translation files eventually.
Apart from translation, I can't think of any other API that would affect old apps right now.
BernhardPosselt commentedon Jun 25, 2015
What about using a proper module loader instead of reinventing the wheel?
PVince81 commentedon Jun 26, 2015
Yes, but the module loader should not be imposed onto app developers.
So far the design goal seemed to be that app developers can use whatever frameworks they want, so whatever solution we find here must be compatible.
In past projects we used requirejs but I don't think it would fit well. If we do, it means app developers need to define their classes as AMD classes.
Do you know any others that could fit better ?
oparoz commentedon Jul 4, 2015
I'm with @Raydiation. Custom sauce is going to increase the complexity and the maintenance level of the project. Educating devs into using a loader is going to have long term benefits for a relatively small price to pay in development time.
BernhardPosselt commentedon Jul 4, 2015
BTW, stumbled over https://www.youtube.com/watch?v=NpMnRifyGyw which shows how jspm works, his examples are in ReactJS but ignore that ;)
How jspm works is that it basically does not care which module system you are using.
Just take a look :)
BernhardPosselt commentedon Jul 4, 2015
Another thing: tons of JS libs and transpilers are not compatible with IE8, can we defer this until IE8 support is dropped?
14 remaining items
PVince81 commentedon Jul 10, 2017
Potentially relevant discussion if we were to use webpack for core and for apps: webpack/webpack#118
PVince81 commentedon Jul 10, 2017
Another worry I have is whether an app's webpack modules would be able to "extend" (in the JS subclass way) classes from the core module. This would require the app bundle to know about the core bundle.
PVince81 commentedon Jul 10, 2017
more here https://stackoverflow.com/q/43163909, seems someone got it to work
PVince81 commentedon Jun 7, 2018
Obsoleted by Phoenix which will come with its own redesigned app loading logic: owncloud/web#2
lock commentedon Jul 30, 2019
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.