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

deepstream-react-connect

v1.2.2

Published

## Usage

Downloads

3

Readme

Deepstream-React Connect

Usage

Connect

import React from 'react';
import ReactDOM from 'react-dom';
import { connect } from 'deepstream-react-connect';
import deepstream from 'deepstream.io-client-js';

class ExampleComponent extends React.Component {
  render() {
    return (<div>{this.props.text}</div>);
  }
}

const client = deepstream("127.0.0.1:6020").login();

const user_id = "user-A";
const device_id = "device-A";

const parameters = { user_id, device_id };

const ConnectedExampleComponent = connect(client, parameters, ExampleComponent);

const element = (<ConnectedExampleComponent text=["Default Text", [":device_id/text", ":user_id/text"]] />);

ReactDOM.render(element, document.getElementById("container"));
// Renders <div>Default Text</div>

client.record.setData(`${user_id}/text`, {value: "User Text"});
// Renders <div>User Text</div>

client.record.setData(`${device_id}/text`, {value: "Device Text"});
// Renders <div>Device Text</div>

Marshaler

import React from 'react';
import ReactDOM from 'react-dom';
import { Marshaler } from 'deepstream-react-connect';

class ExampleComponent extends React.Component {
  render() {
    return (<div {...this.props} />);
  }
}

const marshaler = new Marshaler([ExampleComponent]);

const element = (<ExampleComponent key="exampleKey"><span>Example Text</span></ExampleComponent>);

const instance = marshaler.marshal(component);

//{
//  "type": "ExampleComponent",
//  "props": {},
//  "children": [
//    {
//      "type": "span",
//      "props": {},
//      "children": [
//        {
//          "type": "Text",
//          "props": {
//            "value": "Example Text"
//          },
//          "children": [],
//          "key": "230d9fec7d745d58a0de0558b5d5b6ac"
//        }
//      ],
//      "key": "4045ccd70148bf5a19f5f715c62c6944"
//    }
//  ],
//  "key": "exampleKey"
//}

const element = marshaler.unmarshal(instance);

ReactDOM.render(rehydratedElement, document.getElementById("container"));
// Renders <div><span>Example Text</span></div>  

Hydrator

import React from 'react';
import ReactDOM from 'react-dom';
import { Hydrator } from 'deepstream-react-connect';
import deepstream from 'deepstream.io-client-js';

class ExampleComponent extends React.Component {
  render() {
    return (<div {...this.props} />);
  }
}

const client = deepstream("127.0.0.1:6020").login();

const hydrator = new Hydrator(client, [ExampleComponent]);

const element = (<ExampleComponent key="exampleKey"><span>Example Text</span></ExampleComponent>);

const dehydrateThenRehydrate = async () => {
  const key = await hydrator.dehydrate(component);
  // key === "exampleKey"
  const unsubscribeHydrator = hydrator.hydrate(key, (rehydratedElement) => {
    // Will check cache and return null while loading
    if(rehydratedElement !== null) {
      return;
    }
    // rehydratedElement == element
    ReactDOM.render(rehydratedElement, document.getElementById("container"));
    // Renders <div><span>Example Text</span></div>  
    unsubscribeHydrator(); 
  });
}

dehydrateThenRehydrate();

Hydrator + Marshaler

import React from 'react';
import ReactDOM from 'react-dom';
import { Hydrator } from 'deepstream-react-connect';
import deepstream from 'deepstream.io-client-js';

class ExampleComponent extends React.Component {
  render() {
    return (<div {...this.props} />);
  }
}

const client = deepstream("127.0.0.1:6020").login();

const marshaler = new Marshaler([ExampleComponent]);

const element = (<ExampleComponent key="exampleKey"><span>Example Text</span></ExampleComponent>);

const instance = marshaler.marshal(component);

// Array containing ExampleComponent 
// is not required if marshaling is done earlier.
const hydrator = new Hydrator(client); 

hydrator.store(instance).then(() => console.log("Instance stored."));