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

treble-hook

Package Overview
Dependencies
Maintainers
6
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

treble-hook - npm Package Compare versions

Comparing version 2.0.0-alpha.4 to 2.0.0-alpha.5

2

lib/index.d.ts
import React, { Dispatch, SetStateAction } from 'react';
declare const _default: {
addTopic<T>(topicName: string, defaultValue: T): void;
addTopic<T>(topicName: string, defaultValue: T, initWithSessionStorage?: boolean): void;
getPublisher(topics?: string[] | undefined): React.FunctionComponent<{

@@ -5,0 +5,0 @@ children?: React.ReactNode;

@@ -14,6 +14,13 @@ "use strict";

return {
addTopic(topicName, defaultValue) {
addTopic(topicName, defaultValue, initWithSessionStorage = false) {
if (!topicsCache[topicName]) {
const context = createPublishContext();
const provider = createPublishProvider(context, defaultValue);
let normDefaultValue = defaultValue;
if (initWithSessionStorage) {
const checkValue = sessionStorage.getItem(topicName);
if (checkValue !== null) {
normDefaultValue = checkValue;
}
}
const provider = createPublishProvider(topicName, context, normDefaultValue, initWithSessionStorage);
topicsCache[topicName] = {

@@ -65,5 +72,11 @@ context,

}
function createPublishProvider(TrebleHookContext, defaultValue) {
function createPublishProvider(topicName, TrebleHookContext, defaultValue, initWithSessionStorage = false) {
return (props) => {
const contextState = react_1.useState(defaultValue);
const [stateValue] = contextState;
react_1.useEffect(() => {
if (initWithSessionStorage) {
sessionStorage.setItem(topicName, String(stateValue));
}
}, [stateValue]);
return react_1.default.createElement(TrebleHookContext.Provider, Object.assign({ value: contextState }, props));

@@ -70,0 +83,0 @@ };

{
"name": "treble-hook",
"version": "2.0.0-alpha.4",
"version": "2.0.0-alpha.5",
"description": "Get hooked on simple subscribe-and-publish in ReactJS.",

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

Sorry, the diff of this file is not supported yet

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