Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

RPC: Client side callbacks with server-applied arguments (+ more robust classic RPC) #34

Merged
merged 5 commits into from
Feb 7, 2020

Conversation

wokalski
Copy link
Collaborator

@wokalski wokalski commented Feb 6, 2020

In this PR we add the ability to pass client-side functions to components. It means that we can say on the server that a function defined on the client should be triggered on a component event without an additional server round-trip.

Example

// config.ts
export const config = {
  Main: {
    onPress: localCallback(InputProp.void, { alertText: InputProp.string }),
  },
};
// server/index.ts
type OnPress = ClientSideCallback<void, { alertText: string }>;

const Main = (props: {onPress: OnPress}) => (
  <TouchableOpacity onPress={clientSide(props.onPress, { alertText: "Hello world!" })}>
  </TouchableOpacity>
);
// client/index.ts
<RemoteComponent
  name="Main"
  props={{onPress: (_: void, {alertText}) => {
    Alert.alert(alertText);
  }}}
/>

Copy link
Collaborator Author

@wokalski wokalski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tenor

packages/integration_tests/src/CallbackProp.test.tsx Outdated Show resolved Hide resolved
packages/integration_tests/src/CallbackProp.test.tsx Outdated Show resolved Hide resolved
packages/integration_tests/src/CallbackProp.test.tsx Outdated Show resolved Hide resolved
packages/integration_tests/src/CallbackProp.test.tsx Outdated Show resolved Hide resolved
packages/integration_tests/src/LocalCallback.test.tsx Outdated Show resolved Hide resolved
packages/nars/src/FlatList.re Outdated Show resolved Hide resolved
packages/nars/src/Instance.re Outdated Show resolved Hide resolved
packages/nars/src/Static.tsx Outdated Show resolved Hide resolved
packages/nars/src/Switch.re Outdated Show resolved Hide resolved
packages/nars/src/TsTypes.ts Show resolved Hide resolved
@wokalski wokalski merged commit 5820acb into master Feb 7, 2020
@wokalski wokalski deleted the local-callbacks-and-rpc branch February 7, 2020 15:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant