Skip to content

Commit 67d6877

Browse files
Add withMount in subscribe
1 parent 28baa43 commit 67d6877

File tree

16 files changed

+118
-46
lines changed

16 files changed

+118
-46
lines changed

dist/index.es.js

Lines changed: 29 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 29 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/components/Base/withStore.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
44

55
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; }
66

7+
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
8+
79
import React, { useState, useEffect } from 'react';
810
import { bindActionCreators } from 'redux';
911
import { connect } from 'react-redux';
@@ -67,14 +69,17 @@ export var withStore = function withStore(Component, antFormItemProps) {
6769
valuePropName = withStoreProps.valuePropName;
6870

6971

70-
var excludeProps = ['componentType', 'setDateStore', 'subscribe', 'dispatch', 'dispatchExtraData']; // ...subscribe.map(item => item.name),
72+
var excludeProps = ['componentType', 'setDateStore', 'subscribe'].concat(_toConsumableArray(subscribe.map(function (item) {
73+
return item.name;
74+
})), ['dispatch', 'dispatchExtraData']); // ...subscribe.map(item => item.name),
7175

7276
var isMounted = useMounted();
7377

7478
/** Подписка на изменение props[subscribe.name] в сторе */
7579
subscribe.map(function (item) {
7680
return useEffect(function () {
77-
if (isMounted && item.name) {
81+
// console.log("withStore subscribe: ", item.name, item.withMount);
82+
if ((item.withMount || isMounted) && item.name) {
7883
// console.log("storeHOC => subscribe: ", props[subscribe.name]);
7984
item.onChange && item.onChange({
8085
value: props[item.name],

lib/components/Form/Form.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = [
99

1010
import React, { useState, useEffect } from "react";
1111
import PropTypes from "prop-types";
12+
import { bindActionCreators } from 'redux';
13+
import { connect } from 'react-redux';
1214
import FormItems from "./FormItems";
1315

14-
import { getObjectExcludedProps, noop, notificationError } from "../utils/baseUtils";
16+
import { dispatchToStore, getObjectExcludedProps, noop, notificationError } from "../utils/baseUtils";
1517
import { rtPrefix } from "../utils/variables";
18+
import { setDateStore } from "../../redux/rtd.actions";
1619

1720
var excludeProps = ["componentType", "noPadding", "scrollable", "header", "body", "footer", "loadInitData", "autoSaveForm", "requestSaveForm", "methodSaveForm", "processBeforeSaveForm"];
1821

1922
/** Компонент формы */
2023
var Form = function Form(props) {
21-
var loadInitData = props.loadInitData,
24+
var dispatch = props.dispatch,
25+
setDateStore = props.setDateStore,
26+
loadInitData = props.loadInitData,
2227
header = props.header,
2328
body = props.body,
2429
footer = props.footer,
@@ -102,7 +107,7 @@ var Form = function Form(props) {
102107
_notification.success({
103108
message: "Сохранение прошло успешно"
104109
});
105-
if (props.onFinish) props.onFinish(values);
110+
props.onFinish && props.onFinish(values);
106111
}).catch(function (error) {
107112
return notificationError(error, 'Ошибка при сохранении');
108113
});
@@ -141,7 +146,12 @@ var Form = function Form(props) {
141146
style: _extends({}, antFormProps.style, { width: '100%', height: '100%' }),
142147
initialValues: _extends({}, antFormProps.initialValues, initFormData),
143148
onFinish: onFinish,
144-
onFinishFailed: onFinishFailed
149+
onFinishFailed: onFinishFailed,
150+
onFieldsChange: function onFieldsChange(changedFields, allFields) {
151+
var values = antForm.getFieldsValue();
152+
// console.log('dispatchToStore => ', dispatch, values);
153+
dispatch && dispatchToStore({ dispatch: dispatch, setDateStore: setDateStore, value: values });
154+
}
145155
}),
146156
React.createElement(
147157
React.Fragment,
@@ -200,4 +210,8 @@ Form.defaultProps = {
200210
autoSaveForm: true
201211
};
202212

203-
export default Form;
213+
var mapDispatchToProps = function mapDispatchToProps(dispatch) {
214+
return bindActionCreators({ setDateStore: setDateStore }, dispatch);
215+
};
216+
217+
export default connect(null, mapDispatchToProps)(Form);

lib/components/Modal/Modal.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ var Modal = function Modal(props) {
122122
/** Подписка на изменение props[subscribe.name] в сторе */
123123
subscribe.map(function (item) {
124124
return useEffect(function () {
125-
if (isMounted && item.name) {
125+
// if(!isMounted && !item.name)
126+
// return;
127+
if ((item.withMount || isMounted) && item.name) {
126128
// console.log("storeHOC => subscribe: ", props[subscribe.name]);
127129
item.onChange && item.onChange({
128130
value: props[item.name],

lib/components/Table/AntTable/Table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ var Table = function Table(props) {
196196
/** Подписка на изменение props[subscribe.name] в сторе */
197197
subscribe.map(function (item) {
198198
return useEffect(function () {
199-
if (isMounted && item.name) {
199+
if ((item.withMount || isMounted) && item.name) {
200200
// console.log("Table => useEffect => ", props); //item.name, props[item.name]
201201
var extraData = {};
202202
if (item.extraData) {

lib/components/Table/ReactBaseTable/Table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ var Table = forwardRef(function (props, ref) {
271271
/** Подписка на изменение props[subscribe.name] в сторе */
272272
subscribe.map(function (item) {
273273
return useEffect(function () {
274-
if (isMounted && item.name) {
274+
if ((item.withMount || isMounted) && item.name) {
275275
// console.log("Table => useEffect => [%s] ", item.name, props[item.name]);
276276
var extraData = {};
277277
if (item.extraData) {

lib/components/utils/baseUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export var dispatchToStore = function dispatchToStore(_ref) {
114114
extraData = _ref.extraData;
115115

116116
if (dispatch.path) {
117-
// console.log("storeHOC => dispatchToStore");
117+
// console.log("storeHOC => dispatchToStore", dispatch, setDateStore);
118118
if (dispatch.type === 'event') setDateStore && setDateStore(dispatch.path, {
119119
timestamp: moment(),
120120
// type: dispatch.type,

0 commit comments

Comments
 (0)