Skip to content

Commit

Permalink
updating log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fabOnReact committed Feb 10, 2024
1 parent 93a382b commit 11b76e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/NativeWearConnectivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@ type Payload = Record<string, unknown>;
type ReplyCallback = (reply: Payload) => void;
type ErrorCallback = (err: Error) => void;

const UNHANDLED_CALLBACK =
'The sendMessage function was called without a callback function. ';
const UNHANDLED_CALLBACK_REPLY =
'The callback function was invoked with the payload: ';
const UNHANDLED_CALLBACK_ERROR =
'The callback function was invoked with the error: ';

export const defaultReplyCb = (reply: Payload) => {
console.warn('Unhandled watch reply', reply);
console.log(UNHANDLED_CALLBACK + UNHANDLED_CALLBACK_REPLY, reply);
};
export const defaultErrCb = (err: Error) => {
console.warn('Unhandled sendMessage error', err);
console.warn(UNHANDLED_CALLBACK + UNHANDLED_CALLBACK_ERROR, err);
};

export type SendMessageType = (
export type SendMessage = (
message: Payload,
cb: ReplyCallback,
errCb: ErrorCallback
) => void;

export interface Spec extends TurboModule {
multiply(a: number, b: number): Promise<number>;
sendMessage: SendMessageType;
sendMessage: SendMessage;
}

export default TurboModuleRegistry.getEnforcing<Spec>('WearConnectivity');
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NativeModules, Platform } from 'react-native';
import type { SendMessageType } from './NativeWearConnectivity';
import type { SendMessage } from './NativeWearConnectivity';
import { defaultReplyCb, defaultErrCb } from './NativeWearConnectivity';

const LINKING_ERROR =
Expand Down Expand Up @@ -30,7 +30,7 @@ export function multiply(a: number, b: number): Promise<number> {
return WearConnectivity.multiply(a, b);
}

const sendMessage: SendMessageType = (message, cb, errCb) => {
const sendMessage: SendMessage = (message, cb, errCb) => {
const callbackWithDefault = cb ?? defaultReplyCb;
const errCbWithDefault = errCb ?? defaultErrCb;
return WearConnectivity.sendMessage(
Expand Down

0 comments on commit 11b76e1

Please sign in to comment.