Skip to content

Commit 6989026

Browse files
committed
feat(TouchableOpacity): change the way hook take params
this making it easier to do functional programming
1 parent 989111a commit 6989026

File tree

5 files changed

+91
-24
lines changed

5 files changed

+91
-24
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@types/react-dom": "16.8.4",
2929
"@types/react-native": "0.57.46",
3030
"@typescript-eslint/typescript-estree": "1.6.0",
31+
"patch-package": "6.1.2",
3132
"react": "16.8.6",
3233
"react-dom": "16.8.6",
3334
"react-scripts": "2.1.8",

src/examples/features/welcome.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ export function welcomeTrigger() {
2828
},
2929
)
3030

31-
useTouchableOpacityPress(
32-
{
33-
nameOf: nameOfTouchableOpacity('greet-button'),
34-
},
35-
({ name }) => {
31+
useTouchableOpacityPress(nameOfTouchableOpacity('greet-button'))(
32+
({ name }: any) => {
3633
alert(`${name} is PRESSED! YAY !!!`)
3734
},
3835
)
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { BaraReactTouchableOpacity, TouchableOpacityEventFilter } from './event'
22

3-
export const nameOfTouchableOpacity = (name: string) => (
4-
triggeringEvent: BaraReactTouchableOpacity,
5-
): boolean => (name ? name === triggeringEvent.name : true)
6-
7-
export const classOfTouchableOpacity = (className: string) => (
8-
triggeringEvent: BaraReactTouchableOpacity,
9-
): boolean => (className ? className === triggeringEvent.className : true)
3+
export const nameOfTouchableOpacity = (checkName: string) => ({
4+
name,
5+
}: BaraReactTouchableOpacity) => checkName === name
Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
import { TouchableOpacityEventFilter } from './event'
21
import {
3-
TouchableOpacityPressCallback,
4-
useTouchableOpacityPressTrigger,
5-
} from './trigger'
2+
ActionPipeFunction,
3+
BaraEventPayload,
4+
ConditionPipe,
5+
createPipe,
6+
useAction,
7+
useCondition,
8+
useEvent,
9+
useTrigger,
10+
} from 'bara'
611

7-
export function useTouchableOpacityPress(
8-
eventFilter: TouchableOpacityEventFilter,
9-
callback: TouchableOpacityPressCallback,
10-
) {
11-
return useTouchableOpacityPressTrigger(eventFilter, callback)
12+
import {
13+
BaraReactTouchableOpacity,
14+
TouchableOpacityEventFilter,
15+
useTouchableOpacityPressEvent,
16+
} from './event'
17+
18+
export const useTouchableOpacityPress = (
19+
...conditions: Array<ConditionPipe<BaraReactTouchableOpacity>>
20+
) => (...actions: ActionPipeFunction[]) => {
21+
const piper = (
22+
data: BaraReactTouchableOpacity,
23+
payload: BaraEventPayload<BaraReactTouchableOpacity>,
24+
) => {
25+
createPipe(data, payload)(
26+
...(conditions as any),
27+
)(...actions)
28+
}
29+
useTrigger<BaraReactTouchableOpacity>(() => {
30+
const event = useTouchableOpacityPressEvent()
31+
const action = useAction(piper)
32+
return { event, action }
33+
})
1234
}

yarn.lock

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,11 @@
14531453
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.1.tgz#5c85d662f76fa1d34575766c5dcd6615abcd30d8"
14541454
integrity sha512-FZdkNBDqBRHKQ2MEbSC17xnPFOhZxeJ2YGSfr2BKf3sujG49Qe3bB+rGCwQfIaA7WHnGeGkSijX4FuBCdrzW/g==
14551455

1456+
"@yarnpkg/lockfile@^1.1.0":
1457+
version "1.1.0"
1458+
resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31"
1459+
integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==
1460+
14561461
JSONStream@^1.0.4, JSONStream@^1.3.4:
14571462
version "1.3.5"
14581463
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
@@ -2734,6 +2739,11 @@ ci-info@^1.5.0, ci-info@^1.6.0:
27342739
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.6.0.tgz#2ca20dbb9ceb32d4524a683303313f0304b1e497"
27352740
integrity sha512-vsGdkwSCDpWmP80ncATX7iea5DWQemg1UgCW5J8tqjU3lYw4FBYuj89J0CTVomA7BEfvSZd84GmHko+MxFQU2A==
27362741

2742+
ci-info@^2.0.0:
2743+
version "2.0.0"
2744+
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46"
2745+
integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==
2746+
27372747
cidr-regex@^2.0.10:
27382748
version "2.0.10"
27392749
resolved "https://registry.yarnpkg.com/cidr-regex/-/cidr-regex-2.0.10.tgz#af13878bd4ad704de77d6dc800799358b3afa70d"
@@ -4812,6 +4822,14 @@ find-versions@^3.0.0:
48124822
array-uniq "^2.0.0"
48134823
semver-regex "^2.0.0"
48144824

4825+
find-yarn-workspace-root@^1.2.1:
4826+
version "1.2.1"
4827+
resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-1.2.1.tgz#40eb8e6e7c2502ddfaa2577c176f221422f860db"
4828+
integrity sha512-dVtfb0WuQG+8Ag2uWkbG79hOUzEsRrhBzgfn86g2sJPkzmcpGdghbNTfUKGTxymFrY/tLIodDzLoW9nOJ4FY8Q==
4829+
dependencies:
4830+
fs-extra "^4.0.3"
4831+
micromatch "^3.1.4"
4832+
48154833
flat-cache@^1.2.1:
48164834
version "1.3.4"
48174835
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-1.3.4.tgz#2c2ef77525cc2929007dfffa1dd314aa9c9dee6f"
@@ -4926,7 +4944,7 @@ from2@^2.1.0, from2@^2.1.1:
49264944
inherits "^2.0.1"
49274945
readable-stream "^2.0.0"
49284946

4929-
fs-extra@7.0.1, fs-extra@^7.0.0:
4947+
fs-extra@7.0.1, fs-extra@^7.0.0, fs-extra@^7.0.1:
49304948
version "7.0.1"
49314949
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9"
49324950
integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==
@@ -4935,7 +4953,7 @@ fs-extra@7.0.1, fs-extra@^7.0.0:
49354953
jsonfile "^4.0.0"
49364954
universalify "^0.1.0"
49374955

4938-
fs-extra@^4.0.2:
4956+
fs-extra@^4.0.2, fs-extra@^4.0.3:
49394957
version "4.0.3"
49404958
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"
49414959
integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg==
@@ -5941,6 +5959,13 @@ is-ci@^1.0.10:
59415959
dependencies:
59425960
ci-info "^1.5.0"
59435961

5962+
is-ci@^2.0.0:
5963+
version "2.0.0"
5964+
resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c"
5965+
integrity sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==
5966+
dependencies:
5967+
ci-info "^2.0.0"
5968+
59445969
is-cidr@^2.0.6:
59455970
version "2.0.7"
59465971
resolved "https://registry.yarnpkg.com/is-cidr/-/is-cidr-2.0.7.tgz#0fd4b863c26b2eb2d157ed21060c4f3f8dd356ce"
@@ -6924,6 +6949,13 @@ kind-of@^6.0.0, kind-of@^6.0.2:
69246949
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051"
69256950
integrity sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==
69266951

6952+
klaw-sync@^6.0.0:
6953+
version "6.0.0"
6954+
resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c"
6955+
integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==
6956+
dependencies:
6957+
graceful-fs "^4.1.11"
6958+
69276959
kleur@^2.0.1:
69286960
version "2.0.2"
69296961
resolved "https://registry.yarnpkg.com/kleur/-/kleur-2.0.2.tgz#b704f4944d95e255d038f0cb05fb8a602c55a300"
@@ -8720,6 +8752,25 @@ pascalcase@^0.1.1:
87208752
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
87218753
integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=
87228754

8755+
patch-package@6.1.2:
8756+
version "6.1.2"
8757+
resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.1.2.tgz#9ed0b3defb5c34ecbef3f334ddfb13e01b3d3ff6"
8758+
integrity sha512-5GnzR8lEyeleeariG+hGabUnD2b1yL7AIGFjlLo95zMGRWhZCel58IpeKD46wwPb7i+uNhUI8unV56ogk8Bgqg==
8759+
dependencies:
8760+
"@yarnpkg/lockfile" "^1.1.0"
8761+
chalk "^2.4.2"
8762+
cross-spawn "^6.0.5"
8763+
find-yarn-workspace-root "^1.2.1"
8764+
fs-extra "^7.0.1"
8765+
is-ci "^2.0.0"
8766+
klaw-sync "^6.0.0"
8767+
minimist "^1.2.0"
8768+
rimraf "^2.6.3"
8769+
semver "^5.6.0"
8770+
slash "^2.0.0"
8771+
tmp "^0.0.33"
8772+
update-notifier "^2.5.0"
8773+
87238774
path-browserify@0.0.0:
87248775
version "0.0.0"
87258776
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.0.tgz#a0b870729aae214005b7d5032ec2cbbb0fb4451a"
@@ -10480,7 +10531,7 @@ rgba-regex@^1.0.0:
1048010531
resolved "https://registry.yarnpkg.com/rgba-regex/-/rgba-regex-1.0.0.tgz#43374e2e2ca0968b0ef1523460b7d730ff22eeb3"
1048110532
integrity sha1-QzdOLiyglosO8VI0YLfXMP8i7rM=
1048210533

10483-
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:
10534+
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:
1048410535
version "2.6.3"
1048510536
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab"
1048610537
integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==

0 commit comments

Comments
 (0)