treble-hook
Advanced tools
Comparing version 0.0.27 to 0.0.28
@@ -0,1 +1,7 @@ | ||
/*!* | ||
* Copyright (c) Igneous, Inc. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
export declare enum PubSubTupleIndex { | ||
@@ -7,2 +13,13 @@ State = 0, | ||
export declare type Publish<T> = (newState: T) => void; | ||
export interface TrebleHookConfig { | ||
suppressDupeStateWarning?: boolean; | ||
topicConfig?: TopicConfigMap; | ||
} | ||
export interface TopicConfig { | ||
allowDupeState?: boolean; | ||
} | ||
export interface TopicConfigMap { | ||
[topic: string]: TopicConfig; | ||
} | ||
export declare function configPubSub(config: TrebleHookConfig): void; | ||
export declare function usePubSub<T>(topic: string, defaultState: T): SubscriptionTuple<T>; | ||
@@ -9,0 +26,0 @@ declare type PublicUnsubscribe = () => void; |
"use strict"; | ||
/*!* | ||
* Copyright (c) Igneous, Inc. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,2 +21,3 @@ const react_1 = require("react"); | ||
}; | ||
let trebleHookConfig = {}; | ||
const topics = {}; | ||
@@ -29,4 +36,5 @@ const getCurrentState = (topic) => { | ||
if (topicRecord) { | ||
const allowDupeState = false; | ||
const suppressDupeStateWarning = false; | ||
const allowDupeState = trebleHookConfig.topicConfig | ||
&& trebleHookConfig.topicConfig[topic] | ||
&& trebleHookConfig.topicConfig[topic].allowDupeState; | ||
let proceed = true; | ||
@@ -43,4 +51,5 @@ if (!allowDupeState) { | ||
} | ||
else if (!suppressDupeStateWarning) { | ||
console.warn('[treble-hook] A publish of unchanged state was attempted for topic:', topic, '\n\n\t- If this is desired behavior then set the "allowDupeState" flag to true', '\n\t-To suppress this warning, set either "allowDupeState" or "suppressDupeStateWarning" flag to true'); | ||
else if (!trebleHookConfig.suppressDupeStateWarning) { | ||
console.warn('[treble-hook] A publish of unchanged state was attempted for topic:', topic, '\n\n\t- If this is desired behavior then set the "allowDupeState" flag to true', '\n\t-To suppress this warning, set either "allowDupeState" for topic to true ' + | ||
'or set the global "suppressDupeStateWarning" flag to true'); | ||
} | ||
@@ -58,2 +67,6 @@ } | ||
}; | ||
function configPubSub(config) { | ||
trebleHookConfig = { ...trebleHookConfig, ...config }; | ||
} | ||
exports.configPubSub = configPubSub; | ||
function usePubSub(topic, defaultState) { | ||
@@ -60,0 +73,0 @@ if (arguments.length !== 2) { |
{ | ||
"name": "treble-hook", | ||
"version": "0.0.27", | ||
"version": "0.0.28", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19025
133