Skip to content

Commit

Permalink
馃毀 WIP getting example-rn working
Browse files Browse the repository at this point in the history
  • Loading branch information
mayteio committed Jul 11, 2020
1 parent 330a1ef commit ef30ce5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions example-rn/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ DerivedData
*.ipa
*.xcuserstate

use-pusher

# Android/IntelliJ
#
build/
Expand Down
6 changes: 1 addition & 5 deletions example-rn/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ const config = {
import {PusherProvider} from '@harelpls/use-pusher/react-native';

const App = () => {
return (
<PusherProvider {...config}>
<Screen />
</PusherProvider>
);
return <Screen />;
};

const Screen = () => {
Expand Down
6 changes: 6 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ export default [
exports: "named",
sourcemap: true,
},
{
file: "example-rn/use-pusher/index.js",
format: "cjs",
exports: "named",
sourcemap: true,
},
],
},
];
9 changes: 5 additions & 4 deletions src/PusherProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Pusher, { Options } from "pusher-js";
import { Options } from "pusher-js";
import { PusherContextValues, PusherProviderProps } from "./types";
import React, { useEffect, useRef, useState } from "react";

Expand All @@ -15,13 +15,13 @@ export const __PusherContext = PusherContext;
* @param props Config for Pusher client
*/

export const PusherProvider: React.FC<PusherProviderProps> = ({
export const CorePusherProvider: React.FC<PusherProviderProps> = ({
clientKey,
cluster,
triggerEndpoint,
defer = false,
children,
_PusherRuntime = Pusher,
_PusherRuntime,
...props
}) => {
// errors when required props are not passed.
Expand All @@ -37,11 +37,12 @@ export const PusherProvider: React.FC<PusherProviderProps> = ({
useEffect(() => {
previousConfig.current = props;
});
const [client, setClient] = useState<Pusher | undefined>();
const [client, setClient] = useState<any | undefined>();

useEffect(() => {
// Skip creation of client if deferring, a value prop is passed, or config props are the same.
if (
!_PusherRuntime ||
defer ||
props.value ||
(dequal(previousConfig.current, props) && client !== undefined)
Expand Down
9 changes: 9 additions & 0 deletions src/PusherProviderWeb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";
import Pusher from "pusher-js/react-native";
import { CorePusherProvider } from "./PusherProvider";
import { PusherProviderProps } from "./types";

/** Wrapper around the core PusherProvider that passes in the Pusher react-native lib */
export const PusherProvider: React.FC<PusherProviderProps> = (props) => (
<CorePusherProvider _PusherRuntime={Pusher} {...props} />
);
2 changes: 1 addition & 1 deletion src/__tests__/PusherProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Pusher = require(process.env.JEST_ENV === "rn"

const { PusherProvider } = require(process.env.JEST_ENV === "rn"
? "../react-native/PusherProvider"
: "../PusherProvider");
: "../PusherProviderWeb");

const { render } = require(process.env.JEST_ENV === "rn"
? "@testing-library/react-native"
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// hooks for prod
export * from "./PusherProvider";
export * from "./PusherProviderWeb";
export * from "./usePusher";
export * from "./useChannel";
export * from "./usePresenceChannel";
Expand Down

0 comments on commit ef30ce5

Please sign in to comment.