sergei-maertens / django-systemjs

MIT License
42 stars 5 forks source link

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

Closed svenvandescheur closed 8 years ago

svenvandescheur commented 8 years ago

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 commented 8 years ago

Quick thoughts:

sergei-maertens commented 8 years ago

@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 commented 8 years ago

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