Comments (12)
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.
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.
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.
would be nice if it could read the require.js config file automatically. Would be more DRY
from flow.
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.
@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.
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.
@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.
@totty90 Sorry, does. Not will.
from flow.
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.
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.
@cjdelisle Any idea how to deal with that problem:
Method cannot be called on possibly undefined value undefined
from flow.
Related Issues (20)
- Partial type does not accept plain empty object literal as a default HOT 5
- Cannot return class type as T: Cannot return `root(...)` because a call signature declaring the expected parameter / return type is missing in `SomeModel` [1] but exists in function type [2].Flow(prop-missing) HOT 2
- Does not narrow down type after undefined/falsy check HOT 1
- Recursive/deep Partial HOT 2
- Bugs in negated `instanceof` expressions HOT 1
- [Question]: How to fix flowgen test after flow update HOT 3
- [Discussion]: Any plans to make Flow more interpopble with TS ecosystem? HOT 5
- Higher order type parameter support HOT 1
- Readme links to 404
- Strange index signature error if you use $Keys<O> instead of the equivalent literal union inside $ReadOnlyArray HOT 1
- [homebrew] automation script needs update HOT 2
- "Unxepcted identifier, expected the token ;" when using await inside of ES module HOT 3
- Can't iterate through chars in a string HOT 4
- Flow does not catch invalid switch statements HOT 1
- Conditional type only works if I inline it HOT 5
- Object with null prototype does not extend interface {} HOT 3
- Missing documentation for "render-types"? HOT 2
- Relay + graphql literals HOT 11
- [homebrew] regression test failure with 0.226.0,0.227.0 HOT 2
- FLOW BUG: This is a misplaced error HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flow.