Skip to content

Commit f4ecef1

Browse files
author
Jared Palmer
committed
Closes #6. Add Example with Flow
1 parent d0ea551 commit f4ecef1

File tree

6 files changed

+67
-0
lines changed

6 files changed

+67
-0
lines changed

examples/with-flowtype/.babelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": [
3+
"backpack-core/babel"
4+
],
5+
"plugins": [
6+
"transform-flow-strip-types"
7+
]
8+
}

examples/with-flowtype/.flowconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[ignore]
2+
.*/node_modules/invariant/.*
3+
4+
[include]
5+
6+
[libs]
7+
8+
[options]

examples/with-flowtype/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
build
3+
npm-debug.log

examples/with-flowtype/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# FlowType Example
2+
3+
## How to use
4+
Download the example (or clone the whole project)[https://github.com/palmerhq/backpack.git]:
5+
```bash
6+
curl https://codeload.github.com/palmerhq/backpack/tar.gz/master | tar -xz --strip=2 backpack-master/examples/with-flowtype
7+
cd with-flowtype
8+
```
9+
Install it and run:
10+
```bash
11+
npm install
12+
npm run dev
13+
```
14+
15+
## Idea behind the example
16+
This demonstrates how to add [Flow](https://flowtype.org/) to your Backpack project. Flow is a static type checker that helps you write code
17+
with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept.
18+
19+
To learn more about Flow, take a look at [its documentation](https://flowtype.org/).
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "backpack-examples-with-flowtype",
3+
"version": "0.0.6",
4+
"scripts": {
5+
"start": "node ./build/main.js",
6+
"flow": "flow",
7+
"dev": "backpack dev",
8+
"build": "backpack build",
9+
"postinstall": "backpack build"
10+
},
11+
"license": "MIT",
12+
"dependencies": {
13+
"express": "^4.14.0"
14+
},
15+
"devDependencies": {
16+
"babel-plugin-transform-flow-strip-types": "^6.21.0",
17+
"backpack-core": "0.0.6",
18+
"flow-bin": "^0.37.4"
19+
}
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* @flow */
2+
3+
// This will throw an error when you run `npm run flow`.
4+
// change the return type to `:number`, to remove the error.
5+
function foo(x: string, y: number): string {
6+
return x.length * y;
7+
}
8+
9+
console.log(foo("Hello", 42));

0 commit comments

Comments
 (0)