@pisell/utils 1.0.35 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/miniRedux.js CHANGED
@@ -10,7 +10,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
10
10
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
11
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
12
12
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
- import React, { createContext, useCallback, useReducer, forwardRef } from 'react';
13
+ import React, { createContext, useCallback, useReducer, forwardRef, useRef } from 'react';
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
15
15
  export var miniRedux = function miniRedux(_ref2) {
16
16
  var _ref2$namespace = _ref2.namespace,
@@ -24,6 +24,7 @@ export var miniRedux = function miniRedux(_ref2) {
24
24
  var Provider = function Provider(ComponentUi) {
25
25
  var Components = /*#__PURE__*/forwardRef(function (props, ref) {
26
26
  var _objectSpread2, _ref5;
27
+ var stateRef = useRef();
27
28
  var _useReducer = useReducer(function (state, _ref3) {
28
29
  var type = _ref3.type,
29
30
  payload = _ref3.payload;
@@ -36,11 +37,12 @@ export var miniRedux = function miniRedux(_ref2) {
36
37
  _useReducer2 = _slicedToArray(_useReducer, 2),
37
38
  providerState = _useReducer2[0],
38
39
  dispatch = _useReducer2[1];
40
+ stateRef.current = providerState;
39
41
  var _dispatch = useCallback(function (_ref4) {
40
42
  var type = _ref4.type,
41
43
  payload = _ref4.payload;
42
44
  if (effects[type]) {
43
- effects[type].call(null, payload, dispatch);
45
+ effects[type].call(null, stateRef.current, payload, dispatch);
44
46
  } else if (reducers[type]) {
45
47
  dispatch({
46
48
  type: type,
package/lib/miniRedux.js CHANGED
@@ -42,6 +42,7 @@ var miniRedux = ({
42
42
  const Context = (0, import_react.createContext)({});
43
43
  const Provider = (ComponentUi) => {
44
44
  const Components = (0, import_react.forwardRef)((props, ref) => {
45
+ const stateRef = (0, import_react.useRef)();
45
46
  const [providerState, dispatch] = (0, import_react.useReducer)(
46
47
  (state2, { type, payload }) => {
47
48
  if (reducers[type]) {
@@ -52,9 +53,10 @@ var miniRedux = ({
52
53
  },
53
54
  state
54
55
  );
56
+ stateRef.current = providerState;
55
57
  const _dispatch = (0, import_react.useCallback)(({ type, payload }) => {
56
58
  if (effects[type]) {
57
- effects[type].call(null, payload, dispatch);
59
+ effects[type].call(null, stateRef.current, payload, dispatch);
58
60
  } else if (reducers[type]) {
59
61
  dispatch({ type, payload });
60
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/utils",
3
- "version": "1.0.35",
3
+ "version": "1.0.36",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",