These are chat archives for systemjs/systemjs

21st
Feb 2015
Aleksander Heintz
@Alxandr
Feb 21 2015 00:01
How would I go about getting metadata from a module
Alex
@whitecolor
Feb 21 2015 00:03
@Alxandr you can put a hook on System.translate for example
Aleksander Heintz
@Alxandr
Feb 21 2015 00:03
So you're telling me I have to inject it? That there is no standard way?
Say I want to resolve a module relative to my current running module
Is that not possible?
Alex
@whitecolor
Feb 21 2015 00:05
@Alxandr resolve a name?
there is a System.normalize method to resolve module names
Aleksander Heintz
@Alxandr
Feb 21 2015 00:09
Yeah, but that doesn't take into consideration from which module it's called
For instance: I just tried to do this:
System.normalize('./test').then(r => {
  console.log(`Normalized: ${r}`);
});
The output result is test
Alex
@whitecolor
Feb 21 2015 00:10
System.normalize('./test', 'relative/to/module').then(r => {
console.log(Normalized: ${r});
});
Aleksander Heintz
@Alxandr
Feb 21 2015 00:10
Even though it's beeing run from lib/app/docs/behaviors/sample.
That's all fair, but how do I get the relative/to/module?
Of the current module
Alex
@whitecolor
Feb 21 2015 00:11
is it a common task fo you?
that should work for arbitrary modules?
Aleksander Heintz
@Alxandr
Feb 21 2015 00:12
Well it sort of has to if I want to allow for lazy loading
Sample:
export function createEditor(node) {
  return System.import('./path/to/expensive/module').then(e => e.instansiate(node));
}
Alex
@whitecolor
Feb 21 2015 00:14
Yes I understand, why not put a full name for importing module?
Aleksander Heintz
@Alxandr
Feb 21 2015 00:14
Cause suddenly it's not componentialized anymore
Imagine if this was a jspm component
Then I wouldn't even know the full name
It could be installed as anything
There has to be some way to get the current Module object
Alex
@whitecolor
Feb 21 2015 00:18
well it can propose the solution
Aleksander Heintz
@Alxandr
Feb 21 2015 00:18
Which is?
Alex
@whitecolor
Feb 21 2015 00:19
to modify source of parent module while loading )
Aleksander Heintz
@Alxandr
Feb 21 2015 00:20
That's not really a viable solution
Alex
@whitecolor
Feb 21 2015 00:21
Well probably Guy will advice something else
Or this could be made while build step
Aleksander Heintz
@Alxandr
Feb 21 2015 00:22
That's definitely not viable. Because, as said, I have no idea where this is going to be installed
So it would require all of the installers to setup a install step
Alex
@whitecolor
Feb 21 2015 00:23
when you load the module you know it's normalized name
Aleksander Heintz
@Alxandr
Feb 21 2015 00:23
Yes. But that's never handed to the module itself
Alex
@whitecolor
Feb 21 2015 00:23
so you can find call System.import('../some/relative') and replace it with normalized
Aleksander Heintz
@Alxandr
Feb 21 2015 00:23
So, the only thing I could really do is to create a plugin
Alex
@whitecolor
Feb 21 2015 00:24
Yes. why not?
but probably we are inventing a wheel
Aleksander Heintz
@Alxandr
Feb 21 2015 00:25
Because it's an incredible hack
Is this really how things will work once actual es6 modules comes out?
They'll just blatantly ignore where you're importing stuff from?
With no way of getting at the module name?
Alex
@whitecolor
Feb 21 2015 00:27
You do it dynamilcy, its like you want to know callee function name
Aleksander Heintz
@Alxandr
Feb 21 2015 00:27
No it's not. It's not even close. There is a huge difference between functions and script files.
Alex
@whitecolor
Feb 21 2015 00:29
you can get current script file name?
Aleksander Heintz
@Alxandr
Feb 21 2015 00:30
That's what I'm trying to do
But I can't figure out how.
This is doable in both commonjs and amd
And it's used
Alex
@whitecolor
Feb 21 2015 00:31
how it is done in amd?
systemjs/systemjs#351
Aleksander Heintz
@Alxandr
Feb 21 2015 00:33
define(['require'], function(require) {
  // local instance of "require" always resolves correctly
})
Alex
@whitecolor
Feb 21 2015 00:38
module.id doesn't work for you?
Aleksander Heintz
@Alxandr
Feb 21 2015 00:38
module is not defined
Alex
@whitecolor
Feb 21 2015 01:23
@Alxandr load object is availalbe in a es6 module
with full metadata
Aleksander Heintz
@Alxandr
Feb 21 2015 01:25
As just "load"?
Alex
@whitecolor
Feb 21 2015 01:26
console.log('es6', load.name)
export var test = 'es6!';
Aleksander Heintz
@Alxandr
Feb 21 2015 01:26
ReferenceError: load is not defined
Alex
@whitecolor
Feb 21 2015 01:26
its a dev mode?
Aleksander Heintz
@Alxandr
Feb 21 2015 01:26
No clue what you mean by "dev mode"
Alex
@whitecolor
Feb 21 2015 01:27
well that's strange load.name works for me
Aleksander Heintz
@Alxandr
Feb 21 2015 01:27
Do you import it`?
Alex
@whitecolor
Feb 21 2015 01:28
I require it )
Aleksander Heintz
@Alxandr
Feb 21 2015 01:28
require('load')?
Alex
@whitecolor
Feb 21 2015 01:28
no
I mean I require this ES6 test module
I usually write only CJS
just created test ES6 module
Aleksander Heintz
@Alxandr
Feb 21 2015 01:29
Well, I'm writing es6
So my module is imported by System.register
Alex
@whitecolor
Feb 21 2015 01:30
Well I use a little bit different version off systemjs
Aleksander Heintz
@Alxandr
Feb 21 2015 01:30
I use the one I get from jspm
Alex
@whitecolor
Feb 21 2015 01:31
but the core and regestring system is the systemjs anyway
Alex
@whitecolor
Feb 21 2015 11:07
@guybedford when I do System.delete('module-name'); System.import('module-name') module is loaded and executed again, it works for CJS modules, but doesn't for ES6 (it is not executed) what may be the reason?
Guy Bedford
@guybedford
Feb 21 2015 11:58
@Alxandr this is very much a use case and is being planned in the spec
the spec API for this hasn't been determined yet, although it's looking like it will be a contextual import function similar to AMD
in the mean time we have an API to do this that looks like:
System.import('name', { name: __moduleName })
Note that it will change, but it works today in SystemJS
note that the __moduleName has got some bundling issues at the moment
for example Babel doesn't include it while Tracuer does
perhaps stick to Traceur for the support for now if you can
Luis Martins
@lmartins
Feb 21 2015 16:49
Basic question, im trying to convert my webpack project to jspm, in which i load JS based on the site's current view, like this:
var currentView = document.body.getAttribute('data-jscontroller');
        if ( currentView ) {
            var viewPath = './views/' + currentView;
            require( viewPath );
            App.Views[currentView].init();
        }

Unfortunately this returns an error:

es6-module-loader.js:7:26213
TypeError: Module ./views/home not declared as a dependency.

Is there a way to achieve this?

Alex
@whitecolor
Feb 21 2015 17:35
I'm trying to require CJS module (called config.dev.js) from config.js and get "Uncaught Error: Unable to load dependency config.dev" (I'm importing config.js itself using Sytem.import)
Alex
@whitecolor
Feb 21 2015 20:07
Solved this.
@guybedford but this problem still persist: when I do System.delete('module-name'); System.import('module-name') module is loaded and executed again, it works for CJS modules, but doesn't for ES6 (it is not executed). any suggestions?
Aleksander Heintz
@Alxandr
Feb 21 2015 22:36
@guybedford using Traceur is not really an option at this time
I precompile using babel
But I've managed to hack around it for now
Alex
@whitecolor
Feb 21 2015 22:38
@Alxandr how?
Aleksander Heintz
@Alxandr
Feb 21 2015 22:38
I use metadata from Aurelia
It tags objects it finds with the module path
Alex
@whitecolor
Feb 21 2015 22:39
Aurelia uses systemjs?
Aleksander Heintz
@Alxandr
Feb 21 2015 22:39
jspm, yes
Or amd if that's your poison
It even does cjs
It's written in es6, and transpiled to all of them
Alex
@whitecolor
Feb 21 2015 22:40
btw, what can you say about it (aurelia) comparit to other mv* you used?
Aleksander Heintz
@Alxandr
Feb 21 2015 22:40
It's es6
And uses es6 modules
It's found a (imho) fairly good middleground between web components, and magic
Alex
@whitecolor
Feb 21 2015 22:41
have you tired react?
tried
Aleksander Heintz
@Alxandr
Feb 21 2015 22:41
Yeah. I think react is awesome, for it's use
But I hate building forms in react
Data display is awesome though
Alex
@whitecolor
Feb 21 2015 22:42
how can you compare aurelia vs react?
Aleksander Heintz
@Alxandr
Feb 21 2015 22:42
You can't
It's like comparing jQuery and react
It doesn't make sense
Alex
@whitecolor
Feb 21 2015 22:43
why?
I mean if you have to choose
Aleksander Heintz
@Alxandr
Feb 21 2015 22:44
Ok, so, compare angular and react?
Alex
@whitecolor
Feb 21 2015 22:46
You actually woudn't use both at the same time, right (as it dosn't make much sence) so they can be compared. what would be your considications if you have to choose either for a project?
Aleksander Heintz
@Alxandr
Feb 21 2015 22:46
You can actually, and people are using react with aurelia
Alex
@whitecolor
Feb 21 2015 22:47
but aurelia has its own view engine, why?
Aleksander Heintz
@Alxandr
Feb 21 2015 22:47
Cause why not?
Some people like the react view engine
Also, it's probably faster
At least for now
(Aurelia has yet to start much perf work)
Alex
@whitecolor
Feb 21 2015 22:48
and what can it give for now vs react/flux?
Aleksander Heintz
@Alxandr
Feb 21 2015 22:48
React really shines at doing certain things
Simpler state handling
Like angular
You create your VMs
Which is also the problem that React set out to solve
Cause according to them it doesn't scale for apps with 100k+ vms
But in most cases you don't need that.
You could definitely create something akin to flux to use with aurelia too
Alex
@whitecolor
Feb 21 2015 22:50
100k+ vm on the client. ok
Aleksander Heintz
@Alxandr
Feb 21 2015 22:51
I mean, it's facebook we're talking about here
It's not exactly small pages with 100 users a week
They actually managed to break the limit of methods you could have in an android app
Alex
@whitecolor
Feb 21 2015 22:53
ok, I see, thanks, that is probably a bit off topic for this room)