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

Moon packaged, using Webpack. #89

Closed
hypercub3d opened this issue Jul 20, 2017 · 6 comments
Closed

Moon packaged, using Webpack. #89

hypercub3d opened this issue Jul 20, 2017 · 6 comments
Assignees
Labels

Comments

@hypercub3d
Copy link

hypercub3d commented Jul 20, 2017

I'm attempting to use Moon in an application, where the code is bundled via Webpack, and I am running into an issue.

The problem seems to be that Moon is attempting to make a reference to a global window.Moon instance, which does not exist when it is included via an import call.

The code looks something like this.

import Moon from 'moonjs/dist/moon.js';

// window.Moon = Moon;

Moon.component( 'cart', {
  data() {
    return {
      mylist: [ '1', '2', '3' ]
    }
  },
  template: '<div><ul><li m-for="item in mylist">{{item}}</li></ul></div>',
  computed: {
  }
} );


const moonapp = new Moon( {
  data: {
  },
  computed: {
  },
  hooks: {
    mounted() {
    }
  },
  template: '<div id="moonapp"><cart></cart></div>'
} );

try {
  moonapp.mount( document.querySelector( '#moonapp' ) );
} catch ( error ) {
  console.log( error );
}

export default moonapp;

If I run this code as is, the code builds, and then I get an error in the dev console that states:

======= Moon =======
moonapp.js:43 ReferenceError: Moon is not defined
    at MoonComponent.eval [as $render] (eval at generate (moon.js:2399), <anonymous>:3:179)
    at MoonComponent.Moon.render (moon.js:1919)
    at MoonComponent.Moon.build (moon.js:1962)
    at createComponentFromVNode (moon.js:626)
    at appendChild (moon.js:412)
    at hydrate (moon.js:760)
    at hydrate (moon.js:824)
    at Moon.patch (moon.js:1947)
    at Moon.build (moon.js:1977)
    at Moon.mount (moon.js:1907)

If I simply uncomment the line that defines window.Moon = Moon, then everything works as expected.

This problem also seems to be related to components. If I replace the template code for moonapp to read template: '<div id="moonapp"><span>hello</span></div>', without registering window.Moon, then the app mounts and works properly. But if the <cart> component is invoked in the template, then the error is thrown.

@kbrsh
Copy link
Owner

kbrsh commented Jul 20, 2017

Ahh, the problem here is that m-for uses a runtime helper, Moon.renderLoop, which is undefined in the compiled component render function.

I'm looking into ways to fix this, but for now I would use window.Moon.

@kbrsh kbrsh self-assigned this Jul 20, 2017
@kbrsh kbrsh added the bug label Jul 20, 2017
@kbrsh kbrsh closed this as completed in 290fc93 Jul 20, 2017
@kbrsh
Copy link
Owner

kbrsh commented Jul 20, 2017

@hypercub3d Can you please copy-paste the moon.js file from the dist folder in this repo? It is currently a dev version of the latest build, where this issue should be fixed.

Let me know if the issue persists or is resolved, and I will release it in v0.11.1.

@hypercub3d
Copy link
Author

hypercub3d commented Jul 21, 2017

@kingpixil Yes, I can confirm that its working. :)

Thank you very much for the quick reply and patch.

@kbrsh
Copy link
Owner

kbrsh commented Jul 21, 2017

Awesome! Glad I could help. This will be released in the next version.

@Capital-EX
Copy link

Any estimate as to when 0.11.1 will be released?

@kbrsh
Copy link
Owner

kbrsh commented Oct 13, 2017

@Capital-EX The next release will be a stable v1.0.0. The alpha will be released within the next to weeks, then the beta, and then either a release candidate or a final release 🚀

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

No branches or pull requests

3 participants