Skip to content

JS entry point for apps, make it possible to load resources async #17169

Closed

Description

@PVince81

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.

@DeepDiver1975 @rullzer @Raydiation

Activity

  1. changed the title [-]App JS code must run asynchronously[/-] [+]JS entry point for apps, make it possible to load resources async[/+] on Jun 25, 2015
  2. PVince81 commented on Jun 25, 2015

    @PVince81
    ContributorAuthor

    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.

  3. added this to the milestone on Jun 25, 2015
  4. DeepDiver1975 commented on Jun 25, 2015

    @DeepDiver1975
    Contributor

    Can we have this for 8.2?

  5. modified the milestones: , on Jun 25, 2015
  6. PVince81 commented on Jun 25, 2015

    @PVince81
    ContributorAuthor

    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.

  7. DeepDiver1975 commented on Jun 25, 2015

    @DeepDiver1975
    Contributor

    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.

    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?

  8. PVince81 commented on Jun 25, 2015

    @PVince81
    ContributorAuthor

    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 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.

  9. BernhardPosselt commented on Jun 25, 2015

    @BernhardPosselt
    Contributor

    What about using a proper module loader instead of reinventing the wheel?

  10. PVince81 commented on Jun 26, 2015

    @PVince81
    ContributorAuthor

    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 ?

  11. oparoz commented on Jul 4, 2015

    @oparoz
    Contributor

    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.

  12. BernhardPosselt commented on Jul 4, 2015

    @BernhardPosselt
    Contributor

    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 :)

  13. BernhardPosselt commented on Jul 4, 2015

    @BernhardPosselt
    Contributor

    Another thing: tons of JS libs and transpilers are not compatible with IE8, can we defer this until IE8 support is dropped?

  14. 14 remaining items

  15. modified the milestones: backlog, 10.0 on Jan 27, 2017
  16. PVince81 commented on Jul 10, 2017

    @PVince81
    ContributorAuthor

    Potentially relevant discussion if we were to use webpack for core and for apps: webpack/webpack#118

  17. PVince81 commented on Jul 10, 2017

    @PVince81
    ContributorAuthor

    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.

  18. PVince81 commented on Jul 10, 2017

    @PVince81
    ContributorAuthor
  19. PVince81 commented on Jun 7, 2018

    @PVince81
    ContributorAuthor

    Obsoleted by Phoenix which will come with its own redesigned app loading logic: owncloud/web#2

  20. lock commented on Jul 30, 2019

    @lock

    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.

  21. locked as resolved and limited conversation to collaborators on Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions