Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Change the extension of generated files to .gen.tsx (TS) and .gen.js (Flow/Untyped). #90

Merged
merged 4 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ To import a function `realValue` from JS module `MyMath.ts` (or `MyMath.js`):

```reason
[@genType.import "./MyMath"] /* This is the module to import from. */
[@bs.module "./WrapJsValue"] /* Or "./WrapJsValue.re" for Flow/untyped. */
[@bs.module "./WrapJsValue.regen"] /* Always the name of the current file. */
/* Name and type of the JS value to import. */
external realValue: complexNumber => float = "";

```

Because of the `external` keyword, it's clear from context that this is an import, so you can also just use `@genType` and omit `.import`.

**NOTE** The argument of `@bs.module` is different for the "typescript" and the "flow"/"untyped" back-ends. And must always be the name of the current file (In future, with compiler support, this could be automatically generated).
**NOTE** The argument of `@bs.module`must always be the name of the current file (In future, with compiler support, this could be automatically generated).

### Export and Import React Components

Expand All @@ -149,7 +149,7 @@ To import and wrap a ReactJS component for use by ReasonReact, the type of the `

```reason
[@genType.import "./MyBanner"] /* Module with the JS component to be wrapped. */
[@bs.module "./MyBannerWrapper"] /* Or "./MyBannerWrapper.re" for Flow/untyped. */
[@bs.module "./MyBannerWrapper.regen"] /* Always the name of the current file. */
/* The make function will be automatically generated from the types below. */
external make:
(~show: bool, ~message: option(message)=?, 'a) =>
Expand All @@ -163,8 +163,6 @@ external make:

The type of `make` must have a named argument for each prop in the JS component. Optional props have option type. The `make` function will be generated by `genType`.

**NOTE** The argument of `@bs.module` is different for the "typescript" and the "flow"/"untyped" back-ends.

### Type Expansion and @genType.opaque
If an exported type `persons` references other types in its definition, those types are also exported by default, as long as they are defined in the same file:

Expand Down
18 changes: 18 additions & 0 deletions examples/reason-react-example/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const glob = require("glob");
const fs = require("fs");
const child_process = require("child_process");

glob.glob("src/**/*.bs.js", function(er, files) {
files.forEach(fileBsJs => {
const fileTsx = fileBsJs.substring(0, fileBsJs.length - 6) + "regen.js";
fs.unlink(fileTsx, err => {
return;
});
});
});

const isWindows = /^win/i.test(process.platform);

child_process
.spawn("bsb", ["-clean-world"], { stdio: "inherit", stderr: "inherit", shell: isWindows })
.on("exit", code => process.exit(code));
28 changes: 6 additions & 22 deletions examples/reason-react-example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions examples/reason-react-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "node ../run_bsb.js -make-world",
"start": "node ../run_bsb.js -make-world -w",
"clean": "bsb -clean-world",
"clean": "node clean.js",
"test": "exit 0",
"webpack": "webpack -w",
"webpack:production": "webpack --env.NODE_ENV=production"
Expand All @@ -16,7 +16,6 @@
"author": "",
"license": "MIT",
"dependencies": {
"extension-replace-loader": "^0.0.1",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"reason-react": "^0.5.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// $FlowExpectedError: Reason checked type sufficiently
const TypeExpansionBS = require('./TypeExpansion.bs');

import type {person as Tuples_person} from '../src/basics/Tuples.re';
import type {person as Tuples_person} from '../src/basics/Tuples.regen';

export type personFromTuples = Tuples_person;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ReasonReact = require('reason-react/src/ReasonReact.js');

import type {list} from '../../src/shims/ReasonPervasives.shim';

import type {variant as Component2_variant} from './Component2.re';
import type {variant as Component2_variant} from './Component2.regen';

export type Props = {|+message?: string, +children?: mixed|};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// $FlowExpectedError: Reason checked type sufficiently
const RecordsBS = require('./Records.bs');

import type {weekday as Types_weekday} from './Types.re';
import type {weekday as Types_weekday} from './Types.regen';

export type coord = {|
+x: number,
Expand Down
2 changes: 1 addition & 1 deletion examples/reason-react-example/src/basics/SomeFlowTypes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow strict */

const Types = require("./Types.re");
const Types = require("./Types.regen");

export type anInterestingFlowType = {
an: string,
Expand Down
2 changes: 1 addition & 1 deletion examples/reason-react-example/src/basics/Types.re
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type someMutableFields = {
[@bs.set] "mutable2": string,
};

[@genType.import "./name-with-dashes"] [@bs.module "./Types.re"]
[@genType.import "./name-with-dashes"] [@bs.module "./Types.regen"]
external foo: int => int = "";

[@genType.opaque]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* @flow strict */

import type {someNonStrictType} from './StrictLocal.re';
import type {someNonStrictType} from './StrictLocal.regen';
8 changes: 4 additions & 4 deletions examples/reason-react-example/src/interop/InteropRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const ReactDOM = require("react-dom");
const React = require("react");

const GreetingRe = require("./Greeting.re");
const GreetingRe = require("./Greeting.regen");

// Import a ReasonReact component!
const PageReason = require("./Greeting.re").default;
const PageReason = require("./Greeting.regen").default;

const consoleLog = console.log;

Expand All @@ -19,7 +19,7 @@ const helloWorld = GreetingRe.concat("++", helloWorldList);

const someNumber: number = GreetingRe.testDefaultArgs({ y: 10 });

const WrapJsValue = require("./WrapJsValue.re");
const WrapJsValue = require("./WrapJsValue.regen");

consoleLog("interopRoot.js roundedNumber:", WrapJsValue.roundedNumber);
consoleLog("interopRoot.js areaValue:", WrapJsValue.areaValue);
Expand All @@ -34,7 +34,7 @@ consoleLog("interopRoot.js callMyAreaDirectly:", callMyAreaDirectly);

consoleLog("anInterestingFlowType ", require("../basics/SomeFlowTypes").c);

const Enums = require("../basics/Enums.re");
const Enums = require("../basics/Enums.regen");

consoleLog("Enums: swap(sunday) =", Enums.swap("sunday"));
consoleLog("Enums: fortytwoOK is", Enums.fortytwoOK);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Wrap component MyBanner to be used from Reason.
*/
[@genType.import "./MyBanner.component"] /* Module with the JS component to be wrapped. */
[@bs.module "./MyBannerWrapper.re"] /* This must always be the name of the current module. */
[@bs.module "./MyBannerWrapper.regen"] /* This must always be the name of the current module. */
/* The make function will be automatically generated from the types below. */
external make:
(~show: bool) =>
Expand Down
2 changes: 1 addition & 1 deletion examples/reason-react-example/src/interop/MyMath.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow strict */

const WrapJsValue = require("./WrapJsValue.re");
const WrapJsValue = require("./WrapJsValue.regen");

export const round: number => number = Math.round;

Expand Down
8 changes: 4 additions & 4 deletions examples/reason-react-example/src/interop/WrapJsValue.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions examples/reason-react-example/src/interop/WrapJsValue.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Wrap JS values to be used from Reason
*/
[@genType.import "./MyMath"] /* This is the module to import from. */
[@bs.module "./WrapJsValue.re"] /* This must always be the name of the current module. */
[@bs.module "./WrapJsValue.regen"] /* This must always be the name of the current module. */
/* Name and type of the JS value to bind to. */
external round: float => float = "";

Expand All @@ -13,7 +13,7 @@ type point = {
};

[@genType.import "./MyMath"] /* This is the module to import from. */
[@bs.module "./WrapJsValue.re"] /* This must always be the name of the current module. */
[@bs.module "./WrapJsValue.regen"] /* This must always be the name of the current module. */
/* Name and type of the JS value to bind to. */
external area: point => int = "";

Expand All @@ -30,12 +30,12 @@ let areaValue = area({x: 3, y: None});
type myArray('a);

[@genType.import "./MyMath"] /* This is the module to import from. */
[@bs.module "./WrapJsValue.re"] /* This must always be the name of the current module. */
[@bs.module "./WrapJsValue.regen"] /* This must always be the name of the current module. */
/* Name and type of the JS value to bind to. */
external getValueAtIndex: (myArray(string), int) => string = "";

[@genType.import "./MyMath"] /* This is the module to import from. */
[@bs.module "./WrapJsValue.re"] /* This must always be the name of the current module. */
[@bs.module "./WrapJsValue.regen"] /* This must always be the name of the current module. */
/* Name and type of the JS value to bind to. */
external functionWithRenamedArgument:
string => [@genType.as "ArgRenamed"] ((~argToRename: string) => string) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const CreateBucklescriptBlock = require('bs-platform/lib/js/block.js');
// $FlowExpectedError: Reason checked type sufficiently
const NestedBS = require('./Nested.bs');

import type {variant as Component2_variant} from '../../src/basics/Component2.re';
import type {variant as Component2_variant} from '../../src/basics/Component2.regen';

export opaque type VariantA = mixed;

Expand Down
6 changes: 0 additions & 6 deletions examples/reason-react-example/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ module.exports = {
]
}
}
},
{
loader: "extension-replace-loader",
query: {
exts: [{ from: ".re", to: ".re.js" }]
}
}
]
}
Expand Down
3 changes: 1 addition & 2 deletions examples/typescript-react-example/bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"all": false,
"basic": false
},
"exportInterfaces": false,
"generatedFileExtension": ""
"exportInterfaces": false
},
"name": "sample-typescript-app",
"reason": {
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-react-example/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const child_process = require("child_process");

glob.glob("src/**/*.bs.js", function(er, files) {
files.forEach(fileBsJs => {
const fileTsx = fileBsJs.substring(0, fileBsJs.length - 6) + ".tsx";
const fileTsx = fileBsJs.substring(0, fileBsJs.length - 6) + ".regen.tsx";
fs.unlink(fileTsx, err => {
return;
});
Expand Down
6 changes: 3 additions & 3 deletions examples/typescript-react-example/src/MyBannerWrapper.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/typescript-react-example/src/MyBannerWrapper.re
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
type message = {text: string};

[@genType.import "./MyBanner"] /* Module with the JS component to be wrapped. */
[@bs.module "./MyBannerWrapper"] /* This must always be the name of the current module. */
[@bs.module "./MyBannerWrapper.regen"] /* This must always be the name of the current module. */
/* The make function will be automatically generated from the types below. */
external make:
(~show: bool, ~message: option(message)=?, 'a) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const ReasonReact = require('reason-react/src/ReasonReact.js');

import {Mouse_t as ReactEvent_Mouse_t} from '../src/shims/ReactEvent.shim';

import {coord as Records_coord} from '../src/nested/Records';
import {coord as Records_coord} from '../src/nested/Records.regen';

import {list} from '../src/shims/ReasonPervasives.shim';

import {t as Types_t} from '../src/nested/Types';
import {t as Types_t} from '../src/nested/Types.regen';

// tslint:disable-next-line:interface-over-type-literal
export type person<a> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// tslint:disable-next-line:no-var-requires
const UseWrapJsValueBS = require('./UseWrapJsValue.bs');

import {AbsoluteValue_t as WrapJsValue_AbsoluteValue_t} from './WrapJsValue';
import {AbsoluteValue_t as WrapJsValue_AbsoluteValue_t} from './WrapJsValue.regen';

import {stringFunction as WrapJsValue_stringFunction} from './WrapJsValue';
import {stringFunction as WrapJsValue_stringFunction} from './WrapJsValue.regen';

export const useGetProp: (_1:WrapJsValue_AbsoluteValue_t) => number = UseWrapJsValueBS.useGetProp;

Expand Down
Loading