Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

We need automated module loading based on app+view #10

Closed
svenvandescheur opened this issue Apr 26, 2016 · 3 comments
Closed

We need automated module loading based on app+view #10

svenvandescheur opened this issue Apr 26, 2016 · 3 comments

Comments

@svenvandescheur
Copy link

svenvandescheur commented Apr 26, 2016

Import (poor man's) namespaced modules
import ProjectSetupView as ProjectProjectSetupView from 'projects/ProjectSetupView';

Determine the namespaced module based on current app+view

let app = getApp(),
    view = get View(),
    module = `${app}{view}`;

new module()

The view needs to be know, this can a auto generated mapping or something simple like:
<script data-view="balablala">

@sergei-maertens sergei-maertens changed the title We nee automated module loading based on app+view We need automated module loading based on app+view Apr 26, 2016
@sergei-maertens
Copy link
Owner

Quick thoughts:

  • decorate a (class based) view - optional specification of appname/view name
  • add post-process step to collect registered views and generate ES6 imports based on that
  • prepend 'import' snippet to file-to-be-bundled, so that a nice bundle is generated
  • expose current app / view with new template tag so that it's available in the JS scope.

@sergei-maertens
Copy link
Owner

@svenvandescheur having had some time to let this sink in, I'm not sure why the imports should be auto-generated. Why not create a single bundle then, and start that with all the necessary imports?

Template:

{# templates/base.html #}
...
{% systemjs_import "imtool/main.js" %}
# static/js/main.js (mapped via imtool/main.js -> js/main.js)

import ProjectSetupView as ProjectsProjectSetupView from 'imtool/projects/ProjectSetupView';
import ProjectManagePostsView as ProjectsProjectManagePostsView from 'imtool/projects/ProjectManagePostsView';

let app = getApp(),
    view = getView(),
    module = `${app}${view}`;

new module();

The only thing that is then indeed needed, is exposing the current app and view name, but I'm not getting the feeling that this is something that belongs in django-systemjs anymore.

@sergei-maertens
Copy link
Owner

this is properly implemented in the project that the request originated for, so not something for django-systemjs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants