Skip to content

Commit

Permalink
feat(TouchableOpacity): change the way hook take params
Browse files Browse the repository at this point in the history
this making it easier to do functional programming
  • Loading branch information
nampdn committed Apr 21, 2019
1 parent 989111a commit 6989026
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@types/react-dom": "16.8.4",
"@types/react-native": "0.57.46",
"@typescript-eslint/typescript-estree": "1.6.0",
"patch-package": "6.1.2",
"react": "16.8.6",
"react-dom": "16.8.6",
"react-scripts": "2.1.8",
Expand Down
7 changes: 2 additions & 5 deletions src/examples/features/welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ export function welcomeTrigger() {
},
)

useTouchableOpacityPress(
{
nameOf: nameOfTouchableOpacity('greet-button'),
},
({ name }) => {
useTouchableOpacityPress(nameOfTouchableOpacity('greet-button'))(
({ name }: any) => {
alert(`${name} is PRESSED! YAY !!!`)
},
)
Expand Down
10 changes: 3 additions & 7 deletions src/lib/exports/TouchableOpacity/condition.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { BaraReactTouchableOpacity, TouchableOpacityEventFilter } from './event'

export const nameOfTouchableOpacity = (name: string) => (
triggeringEvent: BaraReactTouchableOpacity,
): boolean => (name ? name === triggeringEvent.name : true)

export const classOfTouchableOpacity = (className: string) => (
triggeringEvent: BaraReactTouchableOpacity,
): boolean => (className ? className === triggeringEvent.className : true)
export const nameOfTouchableOpacity = (checkName: string) => ({
name,
}: BaraReactTouchableOpacity) => checkName === name
40 changes: 31 additions & 9 deletions src/lib/exports/TouchableOpacity/hook.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import { TouchableOpacityEventFilter } from './event'
import {
TouchableOpacityPressCallback,
useTouchableOpacityPressTrigger,
} from './trigger'
ActionPipeFunction,
BaraEventPayload,
ConditionPipe,
createPipe,
useAction,
useCondition,
useEvent,
useTrigger,
} from 'bara'

export function useTouchableOpacityPress(
eventFilter: TouchableOpacityEventFilter,
callback: TouchableOpacityPressCallback,
) {
return useTouchableOpacityPressTrigger(eventFilter, callback)
import {
BaraReactTouchableOpacity,
TouchableOpacityEventFilter,
useTouchableOpacityPressEvent,
} from './event'

export const useTouchableOpacityPress = (
...conditions: Array<ConditionPipe<BaraReactTouchableOpacity>>
) => (...actions: ActionPipeFunction[]) => {
const piper = (
data: BaraReactTouchableOpacity,
payload: BaraEventPayload<BaraReactTouchableOpacity>,
) => {
createPipe(data, payload)(
...(conditions as any),
)(...actions)
}
useTrigger<BaraReactTouchableOpacity>(() => {
const event = useTouchableOpacityPressEvent()
const action = useAction(piper)
return { event, action }
})
}
57 changes: 54 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,11 @@
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.1.tgz#5c85d662f76fa1d34575766c5dcd6615abcd30d8"
integrity sha512-FZdkNBDqBRHKQ2MEbSC17xnPFOhZxeJ2YGSfr2BKf3sujG49Qe3bB+rGCwQfIaA7WHnGeGkSijX4FuBCdrzW/g==

"@yarnpkg/lockfile@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31"
integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==

JSONStream@^1.0.4, JSONStream@^1.3.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
Expand Down Expand Up @@ -2734,6 +2739,11 @@ ci-info@^1.5.0, ci-info@^1.6.0:
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.6.0.tgz#2ca20dbb9ceb32d4524a683303313f0304b1e497"
integrity sha512-vsGdkwSCDpWmP80ncATX7iea5DWQemg1UgCW5J8tqjU3lYw4FBYuj89J0CTVomA7BEfvSZd84GmHko+MxFQU2A==

ci-info@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46"
integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==

cidr-regex@^2.0.10:
version "2.0.10"
resolved "https://registry.yarnpkg.com/cidr-regex/-/cidr-regex-2.0.10.tgz#af13878bd4ad704de77d6dc800799358b3afa70d"
Expand Down Expand Up @@ -4812,6 +4822,14 @@ find-versions@^3.0.0:
array-uniq "^2.0.0"
semver-regex "^2.0.0"

find-yarn-workspace-root@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-1.2.1.tgz#40eb8e6e7c2502ddfaa2577c176f221422f860db"
integrity sha512-dVtfb0WuQG+8Ag2uWkbG79hOUzEsRrhBzgfn86g2sJPkzmcpGdghbNTfUKGTxymFrY/tLIodDzLoW9nOJ4FY8Q==
dependencies:
fs-extra "^4.0.3"
micromatch "^3.1.4"

flat-cache@^1.2.1:
version "1.3.4"
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-1.3.4.tgz#2c2ef77525cc2929007dfffa1dd314aa9c9dee6f"
Expand Down Expand Up @@ -4926,7 +4944,7 @@ from2@^2.1.0, from2@^2.1.1:
inherits "^2.0.1"
readable-stream "^2.0.0"

fs-extra@7.0.1, fs-extra@^7.0.0:
fs-extra@7.0.1, fs-extra@^7.0.0, fs-extra@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9"
integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==
Expand All @@ -4935,7 +4953,7 @@ fs-extra@7.0.1, fs-extra@^7.0.0:
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^4.0.2:
fs-extra@^4.0.2, fs-extra@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"
integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg==
Expand Down Expand Up @@ -5941,6 +5959,13 @@ is-ci@^1.0.10:
dependencies:
ci-info "^1.5.0"

is-ci@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c"
integrity sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==
dependencies:
ci-info "^2.0.0"

is-cidr@^2.0.6:
version "2.0.7"
resolved "https://registry.yarnpkg.com/is-cidr/-/is-cidr-2.0.7.tgz#0fd4b863c26b2eb2d157ed21060c4f3f8dd356ce"
Expand Down Expand Up @@ -6924,6 +6949,13 @@ kind-of@^6.0.0, kind-of@^6.0.2:
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051"
integrity sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==

klaw-sync@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c"
integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==
dependencies:
graceful-fs "^4.1.11"

kleur@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/kleur/-/kleur-2.0.2.tgz#b704f4944d95e255d038f0cb05fb8a602c55a300"
Expand Down Expand Up @@ -8720,6 +8752,25 @@ pascalcase@^0.1.1:
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=

patch-package@6.1.2:
version "6.1.2"
resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.1.2.tgz#9ed0b3defb5c34ecbef3f334ddfb13e01b3d3ff6"
integrity sha512-5GnzR8lEyeleeariG+hGabUnD2b1yL7AIGFjlLo95zMGRWhZCel58IpeKD46wwPb7i+uNhUI8unV56ogk8Bgqg==
dependencies:
"@yarnpkg/lockfile" "^1.1.0"
chalk "^2.4.2"
cross-spawn "^6.0.5"
find-yarn-workspace-root "^1.2.1"
fs-extra "^7.0.1"
is-ci "^2.0.0"
klaw-sync "^6.0.0"
minimist "^1.2.0"
rimraf "^2.6.3"
semver "^5.6.0"
slash "^2.0.0"
tmp "^0.0.33"
update-notifier "^2.5.0"

path-browserify@0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.0.tgz#a0b870729aae214005b7d5032ec2cbbb0fb4451a"
Expand Down Expand Up @@ -10480,7 +10531,7 @@ rgba-regex@^1.0.0:
resolved "https://registry.yarnpkg.com/rgba-regex/-/rgba-regex-1.0.0.tgz#43374e2e2ca0968b0ef1523460b7d730ff22eeb3"
integrity sha1-QzdOLiyglosO8VI0YLfXMP8i7rM=

rimraf@2, rimraf@^2.2.8, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@~2.6.2:
rimraf@2, rimraf@^2.2.8, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2, rimraf@^2.6.3, rimraf@~2.6.2:
version "2.6.3"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab"
integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==
Expand Down

0 comments on commit 6989026

Please sign in to comment.