Skip to content

Commit ba1c4ec

Browse files
authored
Merge pull request #33 from easeq/master
Pass action as a config item to thunk
2 parents cefdd94 + 607bf32 commit ba1c4ec

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

demo/src/schema/basic.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export default {
154154
// Get current table state.
155155
const tableState = getState()[payload.reducerName][payload.name];
156156
confirm('Are your sure you want to delete the selected items?')
157-
? console.log('delete items', payload, getState(), tableState)
157+
? console.log('delete items', config, getState(), tableState)
158158
: console.log(false);
159159

160160
// Filter your selected item ids here for deletion
@@ -174,7 +174,7 @@ export default {
174174
visible: true,
175175
state: false,
176176
thunk: ( config ) => ( dispatch, getState ) => {
177-
console.log('toolbar button click', payload);
177+
console.log('toolbar button click', config);
178178
}
179179
}, {
180180
type: 'resetFilters',
@@ -203,9 +203,9 @@ export default {
203203
save: ( config ) => ( dispatch, getState ) => {
204204
const tableState = getState()[config.reducerName][config.name];
205205
console.log('toolbar save click with modified data', config, tableState.modified);
206-
config.payload.action(MODIFY_DATA)({ clear: true });
206+
config.action(MODIFY_DATA)({ clear: true });
207207
// Dispatch MODIFY_DATA action with clear: true, to reset the modified data
208-
// Dispatch REQUEST_DATA action "config.payload.action(REQUEST_DATA)" to refresh data.
208+
// Dispatch REQUEST_DATA action "config.action(REQUEST_DATA)" to refresh data.
209209
}
210210
}],
211211
],
@@ -281,7 +281,7 @@ export default {
281281
id: '@id',
282282
},
283283
thunk: ( config ) => ( dispatch, getState ) => {
284-
console.log('edit', payload, getState());
284+
console.log('edit', config, getState());
285285
}
286286
}, {
287287
type: 'action',

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@flipbyte/redux-datatable",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"description": "React-Redux data table",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/Renderer/Toolbar/EditableButtons.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const defaultLabels = {
88
save: 'Save'
99
};
1010

11-
const EditableButtons = ({ itemConfig, action, isModified, isEditable, isEditing, internalStateUpdater, thunk }) => {
11+
const EditableButtons = ({ itemConfig, isModified, isEditable, isEditing, internalStateUpdater, thunk }) => {
1212
const { save } = itemConfig;
1313
const labels = _.merge(defaultLabels, itemConfig.labels);
1414
const toggleEditable = () => internalStateUpdater({ type: TOGGLE_EDITABLE });
@@ -21,7 +21,7 @@ const EditableButtons = ({ itemConfig, action, isModified, isEditable, isEditing
2121
</Button>
2222
)}
2323
{ isModified && (
24-
<Button className="rdt-toolbar-button reset-filters" onClick={ save && thunk.bind(this, save, { itemConfig, action }) }>
24+
<Button className="rdt-toolbar-button reset-filters" onClick={ save && thunk.bind(this, save, { itemConfig }) }>
2525
{ labels.save }
2626
</Button>
2727
)}

src/createTable.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ const ReduxDatatable = ( props ) => {
379379
);
380380
};
381381

382-
const prepareActionPayload = ({ reducerName, config: { name, routes, entity }}) => (
383-
( payload = {} ) => ({ name, reducerName, routes, entity, payload })
382+
const prepareActionPayload = ({ reducerName, config: { name, routes, entity }}, action) => (
383+
( payload = {} ) => ({ name, reducerName, routes, entity, payload, action })
384384
);
385385

386386
const mapStateToProps = ( state, { reducerName, config: { name, entity } } ) => ({
@@ -389,14 +389,15 @@ const mapStateToProps = ( state, { reducerName, config: { name, entity } } ) =>
389389
});
390390

391391
const mapDispatchToProps = ( dispatch, ownProps ) => {
392-
let preparePayload = prepareActionPayload(ownProps);
392+
const action = ( type ) => ( payload ) => dispatch(createActionCreator(type)(preparePayload(payload)));
393+
const preparePayload = prepareActionPayload(ownProps, action);
393394
return {
395+
action,
394396
loadData: ( ) => {
395397
dispatch(setPage(preparePayload({ page: 1 })));
396398
dispatch(setLimit(preparePayload({ limit: ownProps.config.pagination.items.limiter.default || 10 })));
397399
dispatch(setSort(preparePayload({ dir: 'desc' })));
398400
},
399-
action: ( type ) => ( payload ) => dispatch(createActionCreator(type)(preparePayload(payload))),
400401
thunk: ( thunk, payload ) => dispatch(thunk(preparePayload(payload)))
401402
};
402403
};

0 commit comments

Comments
 (0)