GithubHelp home page GithubHelp logo

Comments (12)

cjdelisle avatar cjdelisle commented on April 24, 2024 2

It is possible to write flowed code using require.js, you need to fool flow into thinking the code is commonjs, but this is possible in principle using the comment syntax. For example:

/*@flow*/
/*::const define = () => {};*/
define([
    '/common/common.js',
    '/bower_components/jquery/dist/jquery.min.js'
], /*::0);module.exports = (*/ function (Common) {
    /*::Common = require('./common/common.js');*/

    Common.doStuff();
    ///...code goes here

})/*::()*/;

It's a bit annoying that we are forced to use require syntax twice but this is the price to pay for flow and requirejs I guess.

from flow.

cjdelisle avatar cjdelisle commented on April 24, 2024 2

Oh I changed to a different method recently.

/*@flow*/
/*::
const define = () => {};
export type MyType_t = {
    id: number,
    ...
};
*/
define([
    '/common/common.js',
    'jquery',
    '/common/hyperscript.js',
    '/common/Html.js',
    '/common/Ver.js'
], function (Common, $, h, Html, Ver) { /*::});module.exports = (function() {
    const Common = require('./common/common.js');
    const h = require('./common/hyperscript.js');
    const $ = (undefined:any);
    const Html = require('./common/Html.js');
    const Ver = require('./common/Ver.js');
    */

    var Messages = Common.Messages;


    ... code goes here ....

})/*::()*/;

This method seems to work well.

from flow.

aaronshaf avatar aaronshaf commented on April 24, 2024

Under "Required module not found" at http://flowtype.org/docs/troubleshooting.html you'll see some tips for working with node modules. Flow seems to understand some modules but not others (for example, it works with react but not jiff).

from flow.

totty90 avatar totty90 commented on April 24, 2024

would be nice if it could read the require.js config file automatically. Would be more DRY

from flow.

rileylark avatar rileylark commented on April 24, 2024

Working with requirejs would take more than configuring paths - it means understanding AMD.

FWIW, we use requirejs on our project but we've been burned enough times by using the less popular format that I'm considering switching to commonjs anyway.

from flow.

totty90 avatar totty90 commented on April 24, 2024

@rileylark I've tried commonjs on my project but there are some major issues for me:

  • No path aliases (for the server side, at least), which makes me do '../../../../client/some/file';
  • You make change A, build starts, make change B, build ends, you only have change A; You have to make another change to include the change B in your built file.

Can't live with those 2 issues... But you are right, is easier to use browserify.

from flow.

briandipalma avatar briandipalma commented on April 24, 2024

FWIW, we use requirejs on our project but we've been burned enough times by using the less popular format that I'm considering switching to commonjs anyway.

I'd take a look at ES6 modules if you don't mind compiling your code. https://github.com/systemjs/systemjs will allow you to use ES6, AMD, CJS and globals.

from flow.

totty90 avatar totty90 commented on April 24, 2024

@briandipalma Sincerely, this seems amazing. (you say "will", is not yet done?) The only issue now is the build process. Anyone knows how to fix that problem?

You make change A, build starts, make change B, build ends, you only have change A; You have to make another change to include the change B in your built file.

from flow.

briandipalma avatar briandipalma commented on April 24, 2024

@totty90 Sorry, does. Not will.

from flow.

 avatar commented on April 24, 2024

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

from flow.

mroch avatar mroch commented on April 24, 2024

we support commonjs and ES6 these days, and should detect file changes properly. i think this is fixed, but let me know if there's still something missing here.

from flow.

Kiechlus avatar Kiechlus commented on April 24, 2024

@cjdelisle Any idea how to deal with that problem:

image
Method cannot be called on possibly undefined value undefined

from flow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.