├── .gitignore ├── .merlin ├── LICENSE ├── README.md ├── bsconfig.json ├── lib ├── bs │ ├── .bsbuild │ ├── .bsdeps │ ├── .ninja_deps │ ├── .ninja_log │ ├── .sourcedirs.json │ ├── build.ninja │ └── src │ │ ├── ReactNativeWebsocket.cmi │ │ ├── ReactNativeWebsocket.cmj │ │ ├── ReactNativeWebsocket.cmt │ │ ├── ReactNativeWebsocket.mlast │ │ └── ReactNativeWebsocket.mlast.d └── js │ └── src │ └── ReactNativeWebsocket.js ├── package.json ├── src └── ReactNativeWebsocket.re └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | -------------------------------------------------------------------------------- /.merlin: -------------------------------------------------------------------------------- 1 | ####{BSB GENERATED: NO EDIT 2 | FLG -ppx '/Users/trens/dev/bs-react-native-websocket/node_modules/bs-platform/lib/reactjs_jsx_ppx_2.exe' 3 | FLG -ppx /Users/trens/dev/bs-react-native-websocket/node_modules/bs-platform/lib/bsppx.exe 4 | S /Users/trens/dev/bs-react-native-websocket/node_modules/bs-platform/lib/ocaml 5 | B /Users/trens/dev/bs-react-native-websocket/node_modules/bs-platform/lib/ocaml 6 | FLG -nostdlib -color always 7 | FLG -w -30-40+6+7+27+32..39+44+45+101 8 | S /Users/trens/dev/bs-react-native-websocket/node_modules/reason-react/lib/ocaml 9 | B /Users/trens/dev/bs-react-native-websocket/node_modules/reason-react/lib/ocaml 10 | S src 11 | B lib/bs/src 12 | ####BSB GENERATED: NO EDIT} 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Dawid 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bs-react-native-websocket 2 | 3 | ### This package provide Reasonml bindings for [react-native-websocket](https://www.npmjs.com/package/react-native-websocket) component. 4 | 5 | ## Installation 6 | 7 | ``` 8 | $ yarn add bs-react-native-websocket react-native-websocket 9 | ``` 10 | 11 | Then update your `bsconfig.json`, add `bs-react-native-websocket` to bs-dependencies. 12 | 13 | ```json 14 | "bs-dependencies": ["bs-react-native-websocket"] 15 | ``` 16 | 17 | ## Usage 18 | 19 | Usage is very similar to react-native-websocket. 20 | 21 | Example: 22 | 23 | ```js 24 | type state = { 25 | socketRef: ref(option(ReasonReact.reactRef)), 26 | }; 27 | 28 | let setSocketRef = (theRef, {ReasonReact.state}) => 29 | state.socketRef := Js.Nullable.toOption(theRef); 30 | 31 | let component = ReasonReact.reducerComponent("Component"); 32 | 33 | let make = 34 | ( 35 | _children, 36 | ) => { 37 | ...component, 38 | initialState: () => {socketRef: ref(None)}, 39 | render: self => 40 | 41 | Js.log("successfull connection")} 44 | onMessage={ 45 | event => 46 | Js.log(event) // event is a Js.dict object 47 | } 48 | onError={() => Js.log("get error")} 49 | onClose={() => Js.log("connection closed")} 50 | ref={self.handle(setSocketRef)} 51 | reconnect=true 52 | /> 53 | , 54 | }; 55 | ``` 56 | 57 | Example of sending data: 58 | 59 | ```js 60 | // socket is ref to ReactNativeWebsocket component 61 | // data is a stringifiedData that you want to send 62 | ReactNativeWebsocket.send(socketRef, data); 63 | ``` 64 | 65 | ## License 66 | 67 | MIT 68 | 69 | ## Contributing 70 | 71 | PR's are welcome! 72 | -------------------------------------------------------------------------------- /bsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bs-react-native-websocket", 3 | "reason": { 4 | "react-jsx": 2 5 | }, 6 | "bs-dependencies": ["reason-react"], 7 | "refmt": 3, 8 | "bsc-flags": ["-bs-super-errors"], 9 | "sources": [ 10 | { 11 | "dir": "src" 12 | } 13 | ], 14 | "namespace": "true" 15 | } 16 | -------------------------------------------------------------------------------- /lib/bs/.bsbuild: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trancever/bs-react-native-websocket/98df3fd2b8c5de2c5a9cab9ba75a0851b4e5e88c/lib/bs/.bsbuild -------------------------------------------------------------------------------- /lib/bs/.bsdeps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trancever/bs-react-native-websocket/98df3fd2b8c5de2c5a9cab9ba75a0851b4e5e88c/lib/bs/.bsdeps -------------------------------------------------------------------------------- /lib/bs/.ninja_deps: -------------------------------------------------------------------------------- 1 | # ninjadeps 2 |  -------------------------------------------------------------------------------- /lib/bs/.ninja_log: -------------------------------------------------------------------------------- 1 | # ninja log v5 2 | 0 56 1536313220 src/ReactNativeWebsocket.mlast c13cfa3d38ed983c 3 | 56 62 1536313220 src/ReactNativeWebsocket.mlast.d 3ef10ba3fdfee784 4 | 0 16 1536313220 src/ReactNativeWebsocket.cmj 4749099dc0869f8 5 | 0 16 1536313220 /Users/trens/dev/bs-react-native-websocket/lib/js/src/ReactNativeWebsocket.js 4749099dc0869f8 6 | 0 16 1536313220 src/ReactNativeWebsocket.cmi 4749099dc0869f8 7 | -------------------------------------------------------------------------------- /lib/bs/.sourcedirs.json: -------------------------------------------------------------------------------- 1 | { "dirs" : [ "src" ] , "generated" : [] } -------------------------------------------------------------------------------- /lib/bs/build.ninja: -------------------------------------------------------------------------------- 1 | bs_package_flags = -bs-package-name bs-react-native-websocket 2 | src_root_dir = /Users/trens/dev/bs-react-native-websocket 3 | bsc = /Users/trens/dev/bs-react-native-websocket/node_modules/bs-platform/lib/bsc.exe 4 | bsdep = /Users/trens/dev/bs-react-native-websocket/node_modules/bs-platform/lib/bsb_helper.exe 5 | warnings = -w -30-40+6+7+27+32..39+44+45+101 6 | bsc_flags = -nostdlib -I '/Users/trens/dev/bs-react-native-websocket/node_modules/bs-platform/lib/ocaml' -bs-super-errors -color always 7 | ppx_flags = 8 | bs_package_includes = -I /Users/trens/dev/bs-react-native-websocket/node_modules/reason-react/lib/ocaml 9 | bs_package_dev_includes = 10 | namespace = 11 | bsb_dir_group = 0 12 | refmt = /Users/trens/dev/bs-react-native-websocket/node_modules/bs-platform/lib/refmt.exe 13 | reason_react_jsx = -ppx '/Users/trens/dev/bs-react-native-websocket/node_modules/bs-platform/lib/reactjs_jsx_ppx_2.exe' 14 | refmt_flags = --print binary 15 | bsc_lib_includes = -I src 16 | rule build_ast_and_module_sets_from_re 17 | command = ${bsc} -pp "${refmt} ${refmt_flags}" ${reason_react_jsx} ${ppx_flags} ${warnings} ${bsc_flags} -c -o ${out} -bs-syntax-only -bs-binary-ast -impl ${in} 18 | description = Building ${out} 19 | build src/ReactNativeWebsocket.mlast : build_ast_and_module_sets_from_re $src_root_dir/src/ReactNativeWebsocket.re 20 | rule build_deps 21 | command = ${bsdep} ${namespace} -g ${bsb_dir_group} -MD ${in} 22 | description = Building ${out} 23 | build src/ReactNativeWebsocket.mlast.d : build_deps src/ReactNativeWebsocket.mlast 24 | rule build_cmj_cmi 25 | command = ${bsc} ${bs_package_flags} -bs-assume-no-mli -bs-no-builtin-ppx-ml -bs-no-implicit-include ${bs_package_includes} ${bsc_lib_includes} ${bsc_extra_includes} ${warnings} ${bsc_flags} -o ${out} -c ${in} $postbuild 26 | depfile = ${in}.d 27 | description = Building ${out} 28 | build src/ReactNativeWebsocket.cmj | $src_root_dir/lib/js/src/ReactNativeWebsocket.js src/ReactNativeWebsocket.cmi : build_cmj_cmi src/ReactNativeWebsocket.mlast 29 | bsc_flags = $bsc_flags -bs-re-out -bs-super-errors 30 | bs_package_flags = $bs_package_flags -bs-package-output commonjs:lib/js/src 31 | build build.ninja : phony || src/ReactNativeWebsocket.mlast.d 32 | -------------------------------------------------------------------------------- /lib/bs/src/ReactNativeWebsocket.cmi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trancever/bs-react-native-websocket/98df3fd2b8c5de2c5a9cab9ba75a0851b4e5e88c/lib/bs/src/ReactNativeWebsocket.cmi -------------------------------------------------------------------------------- /lib/bs/src/ReactNativeWebsocket.cmj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trancever/bs-react-native-websocket/98df3fd2b8c5de2c5a9cab9ba75a0851b4e5e88c/lib/bs/src/ReactNativeWebsocket.cmj -------------------------------------------------------------------------------- /lib/bs/src/ReactNativeWebsocket.cmt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trancever/bs-react-native-websocket/98df3fd2b8c5de2c5a9cab9ba75a0851b4e5e88c/lib/bs/src/ReactNativeWebsocket.cmt -------------------------------------------------------------------------------- /lib/bs/src/ReactNativeWebsocket.mlast: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trancever/bs-react-native-websocket/98df3fd2b8c5de2c5a9cab9ba75a0851b4e5e88c/lib/bs/src/ReactNativeWebsocket.mlast -------------------------------------------------------------------------------- /lib/bs/src/ReactNativeWebsocket.mlast.d: -------------------------------------------------------------------------------- 1 | src/ReactNativeWebsocket.cmj : -------------------------------------------------------------------------------- /lib/js/src/ReactNativeWebsocket.js: -------------------------------------------------------------------------------- 1 | // Generated by BUCKLESCRIPT VERSION 4.0.5, PLEASE EDIT WITH CARE 2 | 'use strict'; 3 | 4 | var ReasonReact = require("reason-react/lib/js/src/ReasonReact.js"); 5 | var ReactNativeWebsocket = require("react-native-websocket"); 6 | 7 | function make(url, onOpen, onMessage, onError, onClose, reconnect, children) { 8 | return ReasonReact.wrapJsForReason(ReactNativeWebsocket.default, { 9 | url: url, 10 | onOpen: onOpen, 11 | onMessage: onMessage, 12 | onError: onError, 13 | onClose: onClose, 14 | reconnect: reconnect 15 | }, children); 16 | } 17 | 18 | exports.make = make; 19 | /* ReasonReact Not a pure module */ 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bs-react-native-websocket", 3 | "version": "1.0.1", 4 | "description": "Buckle Script bindings for react-native-websocket", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "bsb -make-world -clean-world -w", 8 | "build": "bsb -make-world -clean-world" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/Trancever/bs-react-native-websocket.git" 13 | }, 14 | "author": "Dawid Urbaniak", 15 | "license": "MIT", 16 | "keywards": [ 17 | "bucklescript", 18 | "reasonml", 19 | "react-native-websocket" 20 | ], 21 | "bugs": { 22 | "url": "https://github.com/Trancever/bs-react-native-websocket/issues" 23 | }, 24 | "homepage": "https://github.com/Trancever/bs-react-native-websocket#readme", 25 | "peerDependencies": { 26 | "react-native-websocket": "^1.0.0" 27 | }, 28 | "dependencies": { 29 | "reason-react": "^0.5.3" 30 | }, 31 | "devDependencies": { 32 | "bs-platform": "^4.0.5" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/ReactNativeWebsocket.re: -------------------------------------------------------------------------------- 1 | [@bs.module "react-native-websocket"] 2 | external websocketClass: ReasonReact.reactClass = "default"; 3 | 4 | [@bs.send] external send: (ReasonReact.reactRef, string) => unit = ""; 5 | 6 | type event = Js.Dict.t(string); 7 | 8 | let make = 9 | ( 10 | ~url: string, 11 | ~onOpen: unit => unit, 12 | ~onMessage: event => unit, 13 | ~onError: unit => unit, 14 | ~onClose: unit => unit, 15 | ~reconnect: option(bool)=?, 16 | children, 17 | ) => 18 | ReasonReact.wrapJsForReason( 19 | ~reactClass=websocketClass, 20 | ~props={ 21 | "url": url, 22 | "onOpen": onOpen, 23 | "onMessage": onMessage, 24 | "onError": onError, 25 | "onClose": onClose, 26 | "reconnect": reconnect, 27 | }, 28 | children, 29 | ); -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | bs-platform@^4.0.5: 6 | version "4.0.5" 7 | resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-4.0.5.tgz#d4fd9bbdd11765af5b75110a5655065ece05eed6" 8 | 9 | "js-tokens@^3.0.0 || ^4.0.0": 10 | version "4.0.0" 11 | resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" 12 | 13 | loose-envify@^1.1.0, loose-envify@^1.3.1: 14 | version "1.4.0" 15 | resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" 16 | dependencies: 17 | js-tokens "^3.0.0 || ^4.0.0" 18 | 19 | object-assign@^4.1.1: 20 | version "4.1.1" 21 | resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" 22 | 23 | prop-types@^15.6.2: 24 | version "15.6.2" 25 | resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102" 26 | dependencies: 27 | loose-envify "^1.3.1" 28 | object-assign "^4.1.1" 29 | 30 | "react-dom@>=15.0.0 || >=16.0.0": 31 | version "16.5.0" 32 | resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.5.0.tgz#57704e5718669374b182a17ea79a6d24922cb27d" 33 | dependencies: 34 | loose-envify "^1.1.0" 35 | object-assign "^4.1.1" 36 | prop-types "^15.6.2" 37 | schedule "^0.3.0" 38 | 39 | "react@>=15.0.0 || >=16.0.0": 40 | version "16.5.0" 41 | resolved "https://registry.yarnpkg.com/react/-/react-16.5.0.tgz#f2c1e754bf9751a549d9c6d9aca41905beb56575" 42 | dependencies: 43 | loose-envify "^1.1.0" 44 | object-assign "^4.1.1" 45 | prop-types "^15.6.2" 46 | schedule "^0.3.0" 47 | 48 | reason-react@^0.5.3: 49 | version "0.5.3" 50 | resolved "https://registry.yarnpkg.com/reason-react/-/reason-react-0.5.3.tgz#10601809742fd991109ec9d69ad4baf2c3f17540" 51 | dependencies: 52 | react ">=15.0.0 || >=16.0.0" 53 | react-dom ">=15.0.0 || >=16.0.0" 54 | 55 | schedule@^0.3.0: 56 | version "0.3.0" 57 | resolved "https://registry.yarnpkg.com/schedule/-/schedule-0.3.0.tgz#1be2ab2fc2e768536269ce7326efb478d6c045e8" 58 | dependencies: 59 | object-assign "^4.1.1" 60 | --------------------------------------------------------------------------------