@shipt/osmosis
Advanced tools
Comparing version 1.3.0 to 2.0.0
declare namespace _default { | ||
export { setupStore }; | ||
export { configureSetupStore }; | ||
export { StoreProvider }; | ||
@@ -9,5 +10,6 @@ export { usePersistedState }; | ||
import { setupStore } from "./setupStore.js"; | ||
import { configureSetupStore } from "./setupStore.js"; | ||
import { StoreProvider } from "./storeProvider.js"; | ||
import { usePersistedState } from "./usePersistedState.js"; | ||
import { configureUsePersistedState } from "./usePersistedState.js"; | ||
export { setupStore, StoreProvider, usePersistedState, configureUsePersistedState }; | ||
export { setupStore, configureSetupStore, StoreProvider, usePersistedState, configureUsePersistedState }; |
@@ -18,2 +18,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "configureSetupStore", { | ||
enumerable: true, | ||
get: function get() { | ||
return _setupStore.configureSetupStore; | ||
} | ||
}); | ||
Object.defineProperty(exports, "usePersistedState", { | ||
@@ -41,2 +47,3 @@ enumerable: true, | ||
setupStore: _setupStore.setupStore, | ||
configureSetupStore: _setupStore.configureSetupStore, | ||
StoreProvider: _storeProvider.StoreProvider, | ||
@@ -43,0 +50,0 @@ usePersistedState: _usePersistedState.usePersistedState, |
@@ -0,1 +1,2 @@ | ||
export function configureSetupStore(config: any): void; | ||
export type useCustomHook = (props: any) => any; | ||
@@ -2,0 +3,0 @@ export type SetupStoreConfig = { |
@@ -8,6 +8,8 @@ "use strict"; | ||
}); | ||
exports.setupStore = void 0; | ||
exports.setupStore = exports.configureSetupStore = void 0; | ||
var _react = _interopRequireWildcard(require("react")); | ||
var _excluded = ["children"]; | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
@@ -17,5 +19,20 @@ | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var _defaultConfig = { | ||
proxyEnabled: true | ||
proxyEnabled: true, | ||
legacyReturnStoreAsArray: false | ||
}; | ||
var configureSetupStore = function configureSetupStore(config) { | ||
_defaultConfig = _objectSpread(_objectSpread({}, _defaultConfig), config); | ||
}; | ||
/** | ||
@@ -46,4 +63,8 @@ * @callback useCustomHook | ||
exports.configureSetupStore = configureSetupStore; | ||
var setupStore = function setupStore(useCustomHook) { | ||
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaultConfig; | ||
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
config = _objectSpread(_objectSpread({}, _defaultConfig), config); | ||
var StoreContext = /*#__PURE__*/(0, _react.createContext)(); // If proxy is not supported | ||
@@ -56,5 +77,5 @@ | ||
ref: {} | ||
}; | ||
}; // Legacy Store Provider | ||
var withStoreContext = function withStoreContext(WrappedComponent) { | ||
var withLegacyStoreContext = function withLegacyStoreContext(WrappedComponent) { | ||
return function (props) { | ||
@@ -80,6 +101,45 @@ var storeKey = props.storeKey; | ||
var value = config.legacyReturnStoreAsArray ? [store] : store; | ||
return /*#__PURE__*/_react["default"].createElement(StoreContext.Provider, { | ||
value: [store] | ||
value: value | ||
}, /*#__PURE__*/_react["default"].createElement(WrappedComponent, props)); | ||
}; | ||
}; // New Store Provider | ||
var withStoreContext = function withStoreContext(WrappedComponent) { | ||
var StoreContextWrapper = function StoreContextWrapper(_ref) { | ||
var children = _ref.children, | ||
props = _objectWithoutProperties(_ref, _excluded); | ||
var storeKey = props.storeKey; | ||
var store = useCustomHook(props); | ||
if (!!store.Context) throw new Error("'Context' property is protected and cannot exist on a store object"); | ||
if (!!store.Provider) throw new Error("'Provider' property is protected and cannot exist on a store object"); | ||
if (storeProxy) { | ||
if (storeKey) { | ||
storeProxyObject.ref[storeKey] = store; | ||
} else storeProxyObject.ref = store; | ||
} else { | ||
if (storeKey) { | ||
storeRef[storeKey] = store; | ||
} else { | ||
for (var key in store) { | ||
storeRef[key] = store[key]; | ||
} | ||
} | ||
} | ||
var value = config.legacyReturnStoreAsArray ? [store] : store; | ||
return /*#__PURE__*/_react["default"].createElement(StoreContext.Provider, { | ||
value: value | ||
}, children); | ||
}; | ||
var Wrapper = function Wrapper(props) { | ||
return /*#__PURE__*/_react["default"].createElement(StoreContextWrapper, props, /*#__PURE__*/_react["default"].createElement(WrappedComponent, props)); | ||
}; | ||
return Wrapper; | ||
}; | ||
@@ -92,2 +152,3 @@ | ||
if (property === 'Provider') return withStoreContext; | ||
if (property === 'LegacyProvider') return withLegacyStoreContext; | ||
return target.ref[property]; | ||
@@ -102,2 +163,3 @@ }, | ||
storeRef.Provider = withStoreContext; | ||
storeRef.LegacyProvider = withLegacyStoreContext; | ||
} | ||
@@ -104,0 +166,0 @@ |
{ | ||
"name": "@shipt/osmosis", | ||
"version": "1.3.0", | ||
"version": "2.0.0", | ||
"description": "A lightweight state management library for React and React Native", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -89,3 +89,3 @@ <p align="center"> | ||
export default () => { | ||
const [counterStore] = useContext(CounterStore.Context); | ||
const counterStore = useContext(CounterStore.Context); | ||
let { count } = counterStore.state; | ||
@@ -92,0 +92,0 @@ |
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
24540
382