WhoBuilt

Composable Native APIs

Sep 14, 2018· 29 min· 629 views·Watch on YouTube

Speaker

Andre Staltz, a software developer known for Cycle.js, speaks at Callstack about managing native APIs in React Native through a composable architecture.

Why React Native changes mobile development

Staltz sees React Native as a way to combine ideas from web and native development, with JavaScript reshaping how mobile apps are built. He argues that its challenges extend beyond rendering, state, routing, and requests because teams also work across native APIs, languages, and tools.

Native APIs are imperative singletons

React makes rendering declarative, but APIs such as vibration, toasts, the clipboard, and text-to-speech often require imperative calls. Putting those calls in component lifecycle hooks or action creators works, Staltz says, but couples reusable components to singleton services.

Bubble requests to drivers

Staltz defines composability with a practical test: a component should be useful when moved into its own package and imported elsewhere. His approach has components send requests upward, while singleton drivers handle the real effects, such as triggering vibration. This also allows apps to intercept requests and lets tests check events without a device or emulator.

Use one pattern from leaves to app

Staltz describes bottom-up design as building from leaf components without needing to redesign them as the app grows. In Cycle.js, components follow the same pattern at every level: data flows down and requests bubble up. Each component is a function that takes streams of inputs and produces streams of outputs.

Apply the pattern to a real app

Staltz demonstrates the architecture in an alpha peer-to-peer social app, connecting a news feed and other components through streams. Ordinary React components can still be used inside it, while drivers handle native effects such as the Android status bar. He also suggests React Native's message-passing bridge could support similar interception and testing benefits.

Takeaways

  • Keep imperative native API calls in singleton drivers so components can stay reusable.
  • Send effect requests through the component hierarchy to make them interceptable and testable.
  • Use the same component pattern from leaf to root to support bottom-up design.
  • Model visual native features, such as status bars and toasts, as declarative outputs.
  • Cycle.js can work alongside ordinary React components; migration need not require rewriting them.

Mentioned in this talk

Search inside this talk

What was claimed 7

Related talks