New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-duck

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-duck - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

dist/hooks/useAccessor.d.ts

42

dist/components/Provider.js

@@ -81,3 +81,3 @@ "use strict";

var createAction_1 = require("../createAction");
var useGetter_1 = require("../hooks/useGetter");
var useAccessor_1 = require("../hooks/useAccessor");
var useObservable_1 = require("../hooks/useObservable");

@@ -88,3 +88,3 @@ function Provider(_a) {

var _b = __read(React.useReducer(root.reducer, root.state), 2), state = _b[0], reducerDispatch = _b[1];
var getState = useGetter_1.useGetter(state);
var _c = __read(useAccessor_1.useAccessor(state), 1), getState = _c[0];
var dispatch = React.useCallback(function contextDispatch(action) {

@@ -98,17 +98,33 @@ return __awaiter(this, void 0, void 0, function () {

}, [reducerDispatch]);
var enhanced = React.useMemo(function enhance() {
var _a;
var enhancer = root.enhancer, value = __rest(root, ["enhancer"]);
Object.assign(value, { dispatch: dispatch, getState: getState });
return (_a = enhancer === null || enhancer === void 0 ? void 0 : enhancer(value)) !== null && _a !== void 0 ? _a : value;
var unenhanced = React.useMemo(function getUnenhanced() {
var _ = root.enhancer, value = __rest(root, ["enhancer"]);
return Object.assign(value, { dispatch: dispatch, getState: getState });
}, [dispatch, getState, root]);
React.useEffect(function initialiseContext() {
// Get a reference that will be set once any supplied enhancer is run.
var _d = __read(useAccessor_1.useAccessor(), 2), getEnhanced = _d[0], setEnhanced = _d[1];
// This is the final value to be observed.
// The enhanced value will be given below.
var value = React.useMemo(function getValue() {
return __assign(__assign(__assign({}, unenhanced), getEnhanced()), { state: state });
}, [getEnhanced, state, unenhanced]);
// This is the observable context value that will be enhanced once.
var _e = __read(useObservable_1.useObservable(value), 2), observable = _e[0], publish = _e[1];
// This is called only on the initial render or if the enhancer changes.
// It sets the enhanced value that will supplement the unenhanced value
// on subsequent renders. It needs to be called after an observable is
// created from the value to allow the enhancer subscribe to the value.
React.useEffect(function enhanceAndIntialise() {
var _a, _b;
var enhanced = (_b = (_a = root.enhancer) === null || _a === void 0 ? void 0 : _a.call(root, observable)) !== null && _b !== void 0 ? _b : observable;
setEnhanced === null || setEnhanced === void 0 ? void 0 : setEnhanced(enhanced);
enhanced.dispatch(createAction_1.createAction(actionTypes_1.ActionTypes.INIT)());
}, [enhanced]);
var value = React.useMemo(function getValue() {
return __assign(__assign({}, enhanced), { state: state });
}, [enhanced, state]);
var observable = useObservable_1.useObservable(useGetter_1.useGetter(value));
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[root.enhancer]);
// Notify only on a change to the observed value. This is scheduled after
// the enhance effect to ensure the first render notifies all subscribers.
// eslint-disable-next-line react-hooks/exhaustive-deps
React.useEffect(publish, [observable]);
return React.createElement(Context.Provider, { value: observable }, children);
}
exports.Provider = Provider;

@@ -1,1 +0,1 @@

export declare function useObservable<V>(getter: () => V): V & Observable;
export declare function useObservable<V>(value: V): [V & Observable, () => void];

@@ -73,3 +73,3 @@ "use strict";

};
function useObservable(getter) {
function useObservable(value) {
var _a = useCollection(), observers = _a.value, add = _a.add, remove = _a.remove;

@@ -116,16 +116,10 @@ var subscribe = React.useCallback(function subscribe(listenerOrObserver) {

}, [subscribe]);
var value = getter();
var nextValue = React.useMemo(function getNextValue() {
return __assign(__assign({}, value), observable);
}, [observable, value]);
var next = React.useCallback(function next() {
observers.forEach(function (observer) {
observer.next(nextValue);
});
var observeNext = React.useCallback(function observeNext() {
observers.forEach(function (observer) { return observer.next(nextValue); });
}, [observers, nextValue]);
// Only call observers next for a value change
// eslint-disable-next-line react-hooks/exhaustive-deps
React.useEffect(next, [nextValue]);
return nextValue;
return [nextValue, observeNext];
}
exports.useObservable = useObservable;
{
"name": "react-duck",
"version": "0.5.2",
"version": "0.5.3",
"description": "🦆 React ducks without Redux",

@@ -102,3 +102,3 @@ "author": "iamogbz",

"@types/jest": "^26.0.14",
"@types/node": "^14.10.3",
"@types/node": "^14.11.1",
"@types/react": "^16.9.49",

@@ -130,3 +130,3 @@ "@types/react-is": "^16.7.1",

"rxjs": "^6.6.3",
"semantic-release": "^17.1.1",
"semantic-release": "^17.1.2",
"stylelint": "^13.7.1",

@@ -133,0 +133,0 @@ "stylelint-config-standard": "^20.0.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