npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-sdr

v1.1.1

Published

Server Driven Rendering (SDR) component for React Native

Downloads

6

Readme

Server Driven Rendering (SDR) for React Native

Installation

$ npm install react-native-sdr --save

or

$ yarn add react-native-sdr

Motivation

Server Driven Rendering (SDR) is the process in which an app is told how to render a component remotely. The difference between SDR and Server Side Rendering (SSR) is that in the latter the server does the actual rendering. Imagine yourself building a social network app and you have to implement elements for the timeline. Normally, you would have multiple types of data (news, photo shares, announcements, etc.) and corresponding components for them. However, as time goes you will find the need to push new updates for every new type you add (or even small UI tweaks in certain components). SDR allows you to specify the template on your server and pass it on to your app in order to handle the rendering.

Usage

import SDRContainer from 'react-native-sdr';

  getSDRTemplate() {
    ...
  }

  getSDRTypes() {
    ...
  }

  render() {
    return (
      <SDRContainer
        sdrTemplate={this.getSDRTemplate()}
        sdrTypes={this.getSDRTypes()}
        // ...otherProps 
        />
    )
  }

The component requires a types and a template. Types are all elements that the component has access to (Image, View, etc.). If you want the component to be able to use them during the assembly, you must specify them beforehand.

getSDRTypes() {
    return {
      "Text": Text,
      "View": View,
      "Image": Image,
      "Button": TouchableOpacity,
    }
  }

The template is what you pass from the server to the component. It used for rendering the component. It must look like this:

{
  type: [Mandatory] Component type from predefined types,
  props: [Optional] Props to pass to the component,
  children: [Optional] Array of child objects or a string if text element
}

Template variables are used to access props passed to the component. Example:

// props to component in the app
{
  notification: {
    meta: {
      title: "Liked your comment",
      name: "John Doe"
    }
  }
}

// template from the server
{
  type: "Text",
  children: "Name: ${text::notification.meta.name}, Action: ${text::notification.meta.title}"
}

will render

<Text>Name: John Doe, Action: Liked your comment</Text>

There are multiple types of variables:

| variable | description | | ------ | ------ | |prop::some.path.to.object|Retrieves the object from this.props| |function::some.path.to.function|Retrieves the function from this.props| |${text::some.path.to.text}|Retrieves the text from this.props|

Refer to the Example for more

Available props:

| prop | type | description |default| | ------ | ------ | ------ | ------ | |sdrTemplate|object|The template to render|| |sdrTypes|object|Types to choose from when rendering|{ "View": View }| |shouldComponentUpdate|function|shouldComponentUpdate|() => false|

License

MIT