Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-pubst

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-pubst - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

README.md

2

package.json
{
"name": "react-pubst",
"version": "0.0.1",
"version": "0.0.2",
"description": "Utilities for creating Pubst-aware React components.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -5,2 +5,9 @@ import {Component, createElement} from 'react';

const DEFAULT_CONFIG = {
topic: '',
default: undefined,
doPrime: true,
allowRepeats: false
};
function pubstWrappedComponentBuilder(componentToWrap, subMap) {

@@ -13,4 +20,35 @@

this.subConfigs = {};
Object.keys(subMap).forEach(propName => {
this.state[propName] = pubst.currentVal(subMap[propName]);
const passedConfig = subMap[propName];
const subConfig = {};
if (typeof passedConfig === 'object') {
Object.keys(passedConfig).forEach(configItem => {
if (DEFAULT_CONFIG.hasOwnProperty(configItem)) {
subConfig[configItem] = passedConfig[configItem];
}
});
} else if (typeof passedConfig === 'string' || passedConfig instanceof RegExp) {
subConfig.topic = passedConfig;
} else {
throw new Error(`Pubst subscriber components must be configured with a string, regular expression, or object. Received '${passedConfig}' for prop '${propName}'`);
}
Object.keys(DEFAULT_CONFIG).forEach(configItem => {
if (!subConfig.hasOwnProperty(configItem)) {
subConfig[configItem] = DEFAULT_CONFIG[configItem];
}
});
subConfig.handler = (value) => {
const stateUpdate = {};
stateUpdate[propName] = value;
this.setState(stateUpdate);
}
this.subConfigs[propName] = subConfig;
this.state[propName] = pubst.currentVal(subConfig.topic, subConfig.default);
});

@@ -24,13 +62,8 @@

componentDidMount() {
Object.keys(this.subMap).forEach(propName => {
Object.keys(this.subConfigs).forEach(propName => {
const subConfig = this.subConfigs[propName];
this.unsubs.push(
pubst.subscribe(
this.subMap[propName],
(value) => {
if (value !== this.state[propName]) {
const stateUpdate = {};
stateUpdate[propName] = value;
this.setState(stateUpdate);
}
}
subConfig.topic,
subConfig
)

@@ -37,0 +70,0 @@ );

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc