Skip to content

Commit

Permalink
Adding fp-ts builders
Browse files Browse the repository at this point in the history
  • Loading branch information
pfgray committed Apr 2, 2019
1 parent 0a50e1b commit d98443c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
dist/
.*.swp
yarn-error.log
.vscode/
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "1.6.5",
"description": "",
"license": "MIT",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": {
"name": "Paul Gray",
"email": "[email protected]",
Expand All @@ -15,7 +15,7 @@
"lint-fix": "tslint --project tsconfig-build.json --fix",
"docs:gitbook": "gitbook build ./ docs",
"docs:typedoc": "typedoc --module commonjs --out docs/typedoc/ src/",
"build": "npm-run-all clean build:ts build:dist docs:gitbook",
"build": "npm-run-all clean build:ts build:dist",
"build:ts": "tsc -p tsconfig-build.json",
"build:dist": "webpack --config webpack/bundle.ts",
"clean": "rm -rf lib/",
Expand Down Expand Up @@ -65,12 +65,15 @@
"ts-node": "^3.3.0",
"tslint": "^5.7.0",
"typedoc": "^0.11.1",
"typescript": "^2.5.3",
"typescript": "^3.4.0",
"webpack": "^4.0.0",
"webpack-cli": "^3.0.3",
"webpack-dev-server": "^3.1.4"
},
"dependencies": {},
"dependencies": {
"fp-ts": "^1.15.0",
"fp-ts-contrib": "^0.0.2"
},
"peerDependencies": {
"react": "^15.0.0 || ^16.0.0"
},
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { withPromise, WithPromise } from './lib/withPromise';
import { withState, WithState } from './lib/withState';
import { withLifecycle, WithLifecycle } from './lib/withLifecycle';
import { chainableComponent, DoBuilder } from './lib/fpts';

export {
ChainableComponent,
Expand All @@ -24,5 +25,7 @@ export {
withPromise,
WithPromise,
withLifecycle,
WithLifecycle
WithLifecycle,
chainableComponent,
DoBuilder
};
31 changes: 31 additions & 0 deletions src/lib/fpts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Monad1 } from "fp-ts/lib/Monad";
import { HKT } from 'fp-ts/lib/HKT';
import { ChainableComponent } from "..";
import { Do } from 'fp-ts-contrib/lib/Do';

export const URI = "ChainableComponent";
export type URI = typeof URI;

declare module "fp-ts/lib/HKT" {
interface URI2HKT<A> {
ChainableComponent: ChainableComponent<A>;
}
}

export const chainableComponent: Monad1<URI> = {
URI,
of<A>(a: A) {
return ChainableComponent.of(a);
},
map<A, B>(fa: ChainableComponent<A>, f: (a: A) => B) {
return fa.map(f);
},
ap<A, B>(fab: ChainableComponent<(a: A) => B>, fa: ChainableComponent<A>) {
return fa.ap(fab)
},
chain<A, B>(fa: ChainableComponent<A>, f: (a: A) => ChainableComponent<B>) {
return fa.chain(f)
}
};

export const DoBuilder = Do(chainableComponent)
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
"compileOnSave": false,
"compilerOptions": {
"declaration": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedLocals": false,
"noUnusedParameters": true,
"target": "es5",
"sourceMap": true,
Expand Down
29 changes: 25 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
version "10.3.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.3.5.tgz#8423cdf6e6fb83433e489900d7600d3b61c8260c"

"@types/prop-types@*":
version "15.7.0"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.0.tgz#4c48fed958d6dcf9487195a0ef6456d5f6e0163a"

"@types/ramda@^0.25.36":
version "0.25.36"
resolved "https://registry.yarnpkg.com/@types/ramda/-/ramda-0.25.36.tgz#1ddaf3211c7cd7046fcaefe68c713469ccfc9504"
Expand All @@ -105,12 +109,19 @@
"@types/history" "*"
"@types/react" "*"

"@types/react@*", "@types/react@^16.0.10":
"@types/react@*":
version "16.4.1"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.4.1.tgz#c53bbfb4a78933db587da085ac60dbf5fcf73f8f"
dependencies:
csstype "^2.2.0"

"@types/react@^16.0.10":
version "16.8.10"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.8.10.tgz#1ccb6fde17f71a62ef055382ec68bdc379d4d8d9"
dependencies:
"@types/prop-types" "*"
csstype "^2.2.0"

"@types/recompose@^0.26.4":
version "0.26.4"
resolved "https://registry.yarnpkg.com/@types/recompose/-/recompose-0.26.4.tgz#93dd6c4e28857cd799e9a807a470f66a40c49c3f"
Expand Down Expand Up @@ -2102,6 +2113,16 @@ forwarded@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"

fp-ts-contrib@^0.0.2:
version "0.0.2"
resolved "https://learningobjects.jfrog.io/learningobjects/api/npm/npm-virtual/fp-ts-contrib/-/fp-ts-contrib-0.0.2.tgz#95d3f5a3810020f8aea030bfcbd1efabbfb8124e"
dependencies:
fp-ts "^1.14.3"

fp-ts@^1.14.3, fp-ts@^1.15.0:
version "1.15.0"
resolved "https://learningobjects.jfrog.io/learningobjects/api/npm/npm-virtual/fp-ts/-/fp-ts-1.15.0.tgz#7706d6761cc98ccbece91c2ff2e5a5b924f65f3d"

fragment-cache@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/fragment-cache/-/fragment-cache-0.2.1.tgz#4290fad27f13e89be7f33799c6bc5a0abfff0d19"
Expand Down Expand Up @@ -5540,9 +5561,9 @@ [email protected]:
version "2.7.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836"

typescript@^2.5.3:
version "2.9.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
typescript@^3.4.0:
version "3.4.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.1.tgz#b6691be11a881ffa9a05765a205cb7383f3b63c6"

ua-parser-js@^0.7.18:
version "0.7.18"
Expand Down

0 comments on commit d98443c

Please sign in to comment.