Skip to content

Commit

Permalink
distill into single function
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjoeseph committed May 22, 2021
1 parent 3eca5e9 commit a5c23de
Show file tree
Hide file tree
Showing 57 changed files with 3,942 additions and 10,809 deletions.
50 changes: 11 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@ Parses route strings to a sum type using Matches from fp-ts-routing. Tangentiall
yarn add fp-ts-routing-adt
```

## Note
## Notes

Formatting the `NotFound` type will return '/'
- Formatting the `NotFound` type will return '/'

```ts
import * as R from 'fp-ts-routing'
import { routingFromMatches3 } from 'fp-ts-routing-adt'
import { routingFromMatches } from 'fp-ts-routing-adt'

const landing: R.Match<{}> = R.end
const show: R.Match<{}> = R.lit('show').then(R.end)
const id: R.Match<{ id: number }> = R.int('id').then(R.end)
const landing = R.end // landing: R.Match<{}>
const show = R.lit('show').then(R.end) // show: R.Match<{}>
const id = R.int('id').then(R.end) // id: R.Match<{ id: number }>

const {
parse,
format,
} = routingFromMatches3(
const { parse, format } = routingFromMatches(
['Landing', landing],
['Show', show],
['Id', id],
Expand All @@ -49,33 +46,8 @@ type RouteADT = ReturnType<typeof parse>

```

# Package size
## TODO:

If this package is too big for your website, you can use `codegenWithNumRoutes` to generate a single file.

```ts
// GenerateRoute.ts

import * as fs from 'fs'
import { codegenWithNumRoutes } from 'fp-ts-routing-adt'

fs.writeFile(
`src/RoutingFromMatches100.ts`,
codegenWithNumRoutes(100),
(err) => {
// throws an error, you could also catch it here
if (err) throw err;

// success case, the file was saved
console.log('RoutingFromMatches100.ts saved!');
}
);
```

You can run it on the cli w/ `ts-node`

```
yarn global add ts-node
yarn global add typescript
ts-node GenerateRoute.ts
```
- prevent duplicate routes at the type level?
- implementation using [this](https://ja.nsommer.dk/articles/type-checked-unique-arrays.html) only supports up to 15 routes ([example](https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEpwGZQiOAcmzAFoZVS8BXGYAOwHNCBuAKDZg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O9gNGMD41rc9TAAKxQ7t+2HSdZ0Xf9N1GHdNUOPDs1MAAbFDn32oQ32Y39V043jq1PUTjAAOxQ8t+OgwjjAABwo3tFPo6dv2XQDiz0w9hMkgAnGT9BfT9WO09D4sg5LTC0dGbPGLDBOM3N82LajAtHULiui0DHNq4wtFbYt5OUwrNPm7jOuc0ztFvYt7MM2D1uQ4b-MHSb1Mi3TrtW7RyN23LFNU8L2PK+Hevq6TXva0p2YsEAA))
- if a stable solution is possible, PRs are welcome!
92 changes: 0 additions & 92 deletions src/CodegenWithNumRoutes.ts

This file was deleted.

29 changes: 0 additions & 29 deletions src/RoutingFromMatches1.ts

This file was deleted.

92 changes: 0 additions & 92 deletions src/RoutingFromMatches10.ts

This file was deleted.

99 changes: 0 additions & 99 deletions src/RoutingFromMatches11.ts

This file was deleted.

Loading

0 comments on commit a5c23de

Please sign in to comment.