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

Initial sketch of main function support #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ethul
Copy link
Owner

@ethul ethul commented Nov 6, 2016

@sgentle @Pauan

Sketch on resolving #33. Initial thoughts?

Thanks!

const main = options.mainModule[psModule.name];

if (main) {
js = `${js}\nmodule.exports.${main}(module)();`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this call the function with module? Isn't module.exports.${main} an Eff?

@ethul
Copy link
Owner Author

ethul commented Nov 9, 2016

Thanks for taking a look. I am still experimenting with this, but it seems
useful to pass in the module to the main in order to allow the entry to
invoke "accept" when HMR for webpack is enabled. I didn't immediately see a
way to do this strictly in an FFI function. I am open to ideas though!

On Wednesday, 9 November 2016, Pauan notifications@github.com wrote:

@Pauan commented on this pull request.

In src/index.js
#72 (review):

@@ -182,6 +183,12 @@ function toJavaScript(psModule) {
})
}

  • const main = options.mainModule[psModule.name];
  • if (main) {
  •  js = `${js}\nmodule.exports.${main}(module)();`;
    

Why does this call the function with module? Isn't module.exports.${main}
an Eff?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#72 (review),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAVYy2yjJSK-dQEsYhtRcfkMjpbgbs18ks5q8VmKgaJpZM4KqrCt
.

@ethul
Copy link
Owner Author

ethul commented Nov 9, 2016

To clarify, here is the example entry I was working with:

Example.purs

module Example (Module, example) where

import Prelude (Unit, (>>=), bind, unit, void)

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)

import DOM.Node.Types (Element)
import DOM (DOM)

import React (createElement)
import ReactDOM (render, renderToString)

import Example.App (app)

example :: forall eff. Module -> Eff (dom :: DOM, console :: CONSOLE | eff) Unit
example module_ = do
  let appEl = createElement app unit []

  if isServerSide
     then void (log (renderToString appEl))
     else void (getElementById "app" >>= render appEl)

  hot module_

foreign import isServerSide :: Boolean

foreign import getElementById :: forall eff. String -> Eff eff Element

foreign import hot :: forall eff. Module -> Eff eff Unit

foreign import data Module :: *

Example.js

'use strict';

exports.isServerSide = typeof document === 'undefined';

exports.getElementById = function(id) {
  return function(){
    return document.getElementById(id);
  };
};

exports.hot = function(module) {
  return function(){
    if (module.hot) {
      module.hot.accept();
    }
  };
}

webpack.config.js

...
{ test: /\.purs$/
, loader: 'purs-loader'
, query: { src: [ 'bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs' ]
          ...
          , mainModule: { Example: 'example' }
          }
}
...

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

Successfully merging this pull request may close these issues.

2 participants