can.import #1386

Closed
justinbmeyer opened this Issue Jan 2, 2015 · 4 comments

Comments

Projects
None yet
4 participants
@justinbmeyer
Contributor

justinbmeyer commented Jan 2, 2015

Upcoming features of CanJS will need integration for importing modules. Examples are can-app, and can.stache having the ability to import components it depends on.

I'm proposing a can.import which will work very similar to System.import. It will take a moduleName and return a promise that is resolved with the moduleName:

can.import("can-slider").then(function(CanSlider){

})

The default behavior of can.import will be to use the System loader, if that doesn't exist, it will use AMD, and then CJS.

Other module loaders (such as StealJS) might overwrite can.import to make sure the config has finished loading.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Jan 3, 2015

Contributor

Is it possible to make it load multiple modules can.import("can-slider", "some-other") ?

Contributor

whitecolor commented Jan 3, 2015

Is it possible to make it load multiple modules can.import("can-slider", "some-other") ?

@matthewp

This comment has been minimized.

Show comment
Hide comment
@matthewp

matthewp Jan 5, 2015

Contributor

What will be the use-case for this?

Contributor

matthewp commented Jan 5, 2015

What will be the use-case for this?

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Jan 5, 2015

Contributor

Well what is the use case for this:

can.import("can-slider").then(function(CanSlider){

})

can you give the code example?

Contributor

whitecolor commented Jan 5, 2015

Well what is the use case for this:

can.import("can-slider").then(function(CanSlider){

})

can you give the code example?

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Jan 6, 2015

Contributor

@matthewp @whitecolor this will mostly be an internal method. When a template like explained in #1390 finds a <can-import>, it will call can.import.

<script type='text/stache' id='basics' can-autorender>
    <can-import from="can/view/autorender/tests/basics"/>
    <my-component></my-component>
</script>
<script src='../../../node_modules/steal/steal.js' main='can/view/autorender/'></script>

can.import can be wired to System / steal / amd / anything else.

Is it possible to make it load multiple modules can.import("can-slider", "some-other")

I'm not going to support that. This is an internal method. Use can.when([ can.import(m1), can.import(m2) ])

Contributor

justinbmeyer commented Jan 6, 2015

@matthewp @whitecolor this will mostly be an internal method. When a template like explained in #1390 finds a <can-import>, it will call can.import.

<script type='text/stache' id='basics' can-autorender>
    <can-import from="can/view/autorender/tests/basics"/>
    <my-component></my-component>
</script>
<script src='../../../node_modules/steal/steal.js' main='can/view/autorender/'></script>

can.import can be wired to System / steal / amd / anything else.

Is it possible to make it load multiple modules can.import("can-slider", "some-other")

I'm not going to support that. This is an internal method. Use can.when([ can.import(m1), can.import(m2) ])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment