Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should I import this module from es6? #57

Closed
alesch opened this issue Sep 9, 2015 · 7 comments
Closed

How should I import this module from es6? #57

alesch opened this issue Sep 9, 2015 · 7 comments

Comments

@alesch
Copy link

alesch commented Sep 9, 2015

Thanks for this module!

Importing like this in es5: var I = require('seamless-immutable') gives me:

{ [Function: Immutable]
  isImmutable: [Function: isImmutable],
  ImmutableError: [Function: ImmutableError] }

but I do not find a way to get the same thing in es6.
Doing import * as I from 'seamless-immutable' gives:

{ isImmutable: [Function: isImmutable],
  ImmutableError: [Function: ImmutableError],
  default: 
   { [Function: Immutable]
     isImmutable: [Function: isImmutable],
     ImmutableError: [Function: ImmutableError] } }

I can see that what I need is the default inside but I do not manage to get it
Thank you!.

@crudh
Copy link
Collaborator

crudh commented Sep 9, 2015

@alesch: Does it work if you do: import I from 'seamless-immutable'?

@alesch
Copy link
Author

alesch commented Sep 10, 2015

Using new it works, but it is ugly:

import I from 'seamless-immutable'

let l = new I([1,2,3]);
console.log(l);   // [ 1, 2, 3 ]

When using Ramda I do: import * as R from 'ramda' and it exposes all its functions under R.
I guess the difference is that seamless is not exposing a namespace, but a function.

@crudh
Copy link
Collaborator

crudh commented Sep 10, 2015

I'm using babel and browserify and the following works for me:

import I from "seamless-immutable";

const l = I([1, 2, 3]);
console.log(l);   // [1, 2, 3, __immutable_invariants_hold: true]

@alesch
Copy link
Author

alesch commented Sep 10, 2015

You are right, it works for me too with node. It was my IDE's linter complaining ?!?

In the beginning I tried using nesh, and there import I from ... does not work. But a regular require does.

Sorry about that and thanks for your help!

@alesch alesch closed this as completed Sep 10, 2015
@crudh
Copy link
Collaborator

crudh commented Sep 10, 2015

@alesch: nice! my IDE complains also if I do:
import I from "seamless-immutable";
but if I do:
import immutable from "seamless-immutable";
it doesnt. It's because functions with a name that starts with an uppercase letter are supposed to be constructor functions and used with new.

@alesch
Copy link
Author

alesch commented Sep 10, 2015

Super!

@jbmeslin
Copy link

Hi,

how replace a require('seamless-immutable').static with and ES6 import ?

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

No branches or pull requests

3 participants