All Projects โ†’ cawfree โ†’ React Native Wormhole

cawfree / React Native Wormhole

Licence: mit
โš›๏ธ ๐ŸŒŒ Inter-dimensional Portals for React Native. ๐Ÿ‘ฝ ๐Ÿ––

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Native Wormhole

Vue Loaders
Vue + loaders.css
Stars: โœญ 127 (-4.51%)
Mutual labels:  plugin, component, loader
Awloader
AWLoader is a UI Component that allows you to integrate loader that fits your needs within your app.
Stars: โœญ 11 (-91.73%)
Mutual labels:  component, loader
Why Did You Render
why-did-you-render by Welldone Software monkey patches React to notify you about potentially avoidable re-renders. (Works with React Native as well.)
Stars: โœญ 7,695 (+5685.71%)
Mutual labels:  render, component
React Async Fetcher
React component for asynchronous loading/fetch online data
Stars: โœญ 50 (-62.41%)
Mutual labels:  component, loader
Grassbending
A replacement for Unity's terrain grass shader with alpha blended rendering and touch bending effect
Stars: โœญ 397 (+198.5%)
Mutual labels:  plugin, dynamic
Ng Dynamic Component
Dynamic components with full life-cycle support for inputs and outputs for Angular
Stars: โœญ 396 (+197.74%)
Mutual labels:  dynamic, component
Carbon
๐Ÿšด A declarative library for building component-based user interfaces in UITableView and UICollectionView.
Stars: โœญ 1,034 (+677.44%)
Mutual labels:  render, component
Vue Plugin Template
๐Ÿš€ Solid foundation to start a Vue plugin with the best developer experience and a focus on performance
Stars: โœญ 189 (+42.11%)
Mutual labels:  plugin, component
React Native Skeleton Content Nonexpo
A customizable skeleton-like loading placeholder for react native projects not using expo.
Stars: โœญ 92 (-30.83%)
Mutual labels:  component, loader
Homebridge Fritz Platform
AiO Homebridge dynamic platform plugin for AVM hardware like Fritz!Box, Fritz!Repeater etc.
Stars: โœญ 101 (-24.06%)
Mutual labels:  plugin, dynamic
Vue Api Request
Control your API calls by using an amazing component which supports axios and vue-resource
Stars: โœญ 116 (-12.78%)
Mutual labels:  component, loader
Vuewordcloud
Generates a cloud out of the words.
Stars: โœญ 284 (+113.53%)
Mutual labels:  plugin, component
Vue Context Menu
๐Ÿ—ƒ๏ธ Vue 2.x ๅณ้”ฎ่œๅ•็ป„ไปถ๏ผŒ่œๅ•ๅ†…ๅฎนๅฏไปฅ้šๆ„่‡ชๅฎšไน‰
Stars: โœญ 279 (+109.77%)
Mutual labels:  plugin, component
Goloader
load and run golang code at runtime. (WARNING: this repo has not been maintained for a long time, please take a look at https://github.com/pkujhd/goloader)
Stars: โœญ 564 (+324.06%)
Mutual labels:  plugin, dynamic
lp-loader
Frictionless language packs for Webpack.
Stars: โœญ 14 (-89.47%)
Mutual labels:  dynamic, loader
Vue Lazy Component
๐ŸŒ Vue.js 2.x ็ป„ไปถ็บงๆ‡’ๅŠ ่ฝฝๆ–นๆกˆ-Vue.js 2.x component level lazy loading solution
Stars: โœญ 915 (+587.97%)
Mutual labels:  plugin, component
Http Loader
A loader for ngx-translate that loads translations with http calls
Stars: โœญ 170 (+27.82%)
Mutual labels:  plugin, loader
V Chart Plugin
Easily bind a chart to the data stored in your Vue.js components.
Stars: โœญ 188 (+41.35%)
Mutual labels:  plugin, component
Reason Loadable
๐Ÿ”ฅ Suspense/Lazy for ReasonReact.
Stars: โœญ 88 (-33.83%)
Mutual labels:  dynamic, component
Axbaseplugin
Android Plugin Framework
Stars: โœญ 122 (-8.27%)
Mutual labels:  plugin, dynamic

๐ŸŒŒ react-native-wormhole

A Wormhole allows your โš›๏ธ React Native application to consume components from a remote URL as if it were a local import, enabling them to easily become remotely configurable at runtime!

๐ŸŽฌ Watch the Demo!

โš ๏ธ Implementors must take care to protect their Wormholes from arbitrary code execution. Insufficient protection will put your user's data and device at risk. ๐Ÿ’€ Please see Verification and Signing for more information.

๐Ÿš€ Getting Started

Using Yarn:

yarn add react-native-wormhole

Next, you'll need a component to serve. Let's create a quick project to demonstrate how this works:

mkdir my-new-wormhole
cd my-new-wormhole
yarn init
yarn add --dev @babel/core @babel/cli @babel/preset-env @babel/preset-react

That should be enough. Inside my-new-wormhole/, let's quickly create a simple component:

my-new-wormhole/MyNewWormhole.jsx:

import * as React from 'react';
import { Animated, Alert, TouchableOpacity } from 'react-native';

function CustomButton() {
  return (
    <TouchableOpacity onPress={() => Alert.alert('Hello!')}>
      <Animated.Text children="Click here!" />
    </TouchableOpacity>
  );
}

export default function MyNewWormhole() {
  const message = React.useMemo(() => 'Hello, world!', []);
  return (
    <Animated.View style={{ flex: 1, backgroundColor: 'red' }}>
      <Animated.Text>{message}</Animated.Text>
      <CustomButton />
    </Animated.View>
  );
}

๐Ÿค” What syntax am I allowed to use?

By default, you can use all functionality exported by react and react-native. The only requirement is that you must export default the Component that you wish to have served through the Wormhole.

Now our component needs to be transpiled. Below, we use Babel to convert MyNewWormhole into a format that can be executed at runtime:

npx babel [email protected]/preset-env,@babel/preset-react MyNewWormhole.jsx -o MyNewWormhole.js

After doing this, we'll have produced MyNewWormhole.js, which has been expressed in a format that is suitable to serve remotely. If you're unfamiliar with this process, take a quick look through the contents of the generated file to understand how it has changed.

Next, you'd need to serve this file somewhere. For example, you could save it on GitHub, IPFS or on your own local server. To see an example of this, check out the Example Server.

๐Ÿ‘ฎ Security Notice

In production environments, you must serve content using HTTPS to prevent Man in the Middle attacks. Additionally, served content must be signed using public-key encryption to ensure authenticity of the returned source code. A demonstration of this approach using Ethers is shown in the Example App.

Finally, let's render our <App />! For the purpose of this tutorial, let's assume the file is served at https://cawfree.com/MyNewWormhole.jsx:

import * as React from 'react';
import { createWormhole } from 'react-native-wormhole';

const { Wormhole } = createWormhole({
  verify: async () => true,
});

export default function App() {
  return <Wormhole source={{ uri: 'https://cawfree.com/MyNewWormhole.jsx' }} />;
}

And that's everything! Once our component has finished downloading, it'll be mounted and visible on screen. ๐Ÿš€

๐Ÿ”ฉ Configuration

๐ŸŒŽ Global Scope

By default, a Wormhole is only capable of consuming global functionality from two different modules; react and react-native, meaning that only "vanilla" React Native functionality is available. However, it is possible to introduce support for additional modules. In the snippet below, we show how to allow a Wormhole to render a WebView:

const { Wormhole } = createWormhole({
+  global: {
+    require: (moduleId: string) => {
+      if (moduleId === 'react') {
+        return require('react');
+      } else if (moduleId === 'react-native') {
+        return require('react-native');
+      } else if (moduleId === 'react-native-webview') {
+        return require('react-native-webview);
+      }
+      return null;
+    },
+  },
  verify: async () => true,
});

โš ๏ธ Version changes to react, react-native or any other dependencies your Wormholes consume may not be backwards-compatible. It's recommended that APIs serving content to requestors verify the compatibility of the requester version to avoid serving incompatible content. react-native-wormhole is not a package manager!

๐Ÿ” Verification and Signing

Calls to createWormhole must at a minimum provide a verify function, which has the following declaration:

readonly verify: (response: AxiosResponse<string>) => Promise<boolean>;

This property is used to determine the integrity of a response, and is responsible for identifying whether remote content may be trusted for execution. If the async function does not return true, the request is terminated and the content will not be rendered via a Wormhole. In the Example App, we show how content can be signed to determine the authenticity of a response:

+ import { ethers } from 'ethers';
+ import { SIGNER_ADDRESS, PORT } from '@env';

const { Wormhole } = createWormhole({
+  verify: async ({ headers, data }: AxiosResponse) => {
+    const signature = headers['x-csrf-token'];
+    const bytes = ethers.utils.arrayify(signature);
+    const hash = ethers.utils.hashMessage(data);
+    const address = await ethers.utils.recoverAddress(
+      hash,
+      bytes
+    );
+    return address === SIGNER_ADDRESS;
+  },
});

In this implementation, the server is expected to return a HTTP response header x-csrf-token whose value is a signedMessage of the response body. Here, the client computes the expected signing address of the served content using the digest stored in the header.

If the recovered address is not trusted, the script will not be executed.

๐ŸŽ๏ธ Preloading

Making a call to createWormhole() also returns a preload function which can be used to asynchronously cache remote JSX before a Wormhole has been mounted:

const { preload } = createWormhole({ verify: async () => true });

(async () => {
  try {
    await preload('https://cawfree.com/MyNewWormhole.jsx');
  } catch (e) {
    console.error('Failed to preload.');
  }
})();

Wormholes dependent upon the external content will subsequently render immediately if the operation has completed in time. Meanwhile, concurrent requests to the same resource will be deduped.

โœŒ๏ธ License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].