From ccbf411168a198b01dcf7aa47a646ed747b4a62c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 4 Jun 2015 13:16:19 +0200 Subject: [PATCH] fixed store bindings --- js/app.js | 20 ++++++++++++++++++ .../piece_list_bulk_modal.js | 21 +++++++++---------- .../ascribe_table/table_item_wrapper.js | 1 - js/components/edition_container.js | 20 ++++++++++-------- js/components/header.js | 4 ++++ js/components/piece_list.js | 2 +- 6 files changed, 46 insertions(+), 22 deletions(-) diff --git a/js/app.js b/js/app.js index d37e1a62..30d2f486 100644 --- a/js/app.js +++ b/js/app.js @@ -14,6 +14,26 @@ import alt from './alt'; import fetch from './utils/fetch'; import AlertDismissable from './components/ascribe_forms/alert'; +/* + Taken from + http://stackoverflow.com/questions/30613447/how-to-debug-reactjss-setstate?noredirect=1#comment49301874_30613447 + + + +*/ + +var warn = console.warn; +console.warn = function(warning) { + if (/(setState)/.test(warning)) { + throw new Error(warning); + } + warn.apply(console, arguments); +}; + +/* + + + */ fetch.defaults({ urlMap: ApiUrls, diff --git a/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js b/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js index 896882df..75695058 100644 --- a/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js +++ b/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js @@ -15,7 +15,10 @@ let PieceListBulkModal = React.createClass({ }, getInitialState() { - return EditionListStore.getState(); + return { + editions: EditionListStore.getState(), + user: UserStore.getState() + }; }, onChange(state) { @@ -37,9 +40,9 @@ let PieceListBulkModal = React.createClass({ let selectedEditionList = []; Object - .keys(this.state.editionList) + .keys(this.state.editions.editionList) .forEach((key) => { - let filteredEditionsForPiece = this.state.editionList[key].filter((edition) => edition.selected); + let filteredEditionsForPiece = this.state.editions.editionList[key].filter((edition) => edition.selected); selectedEditionList = selectedEditionList.concat(filteredEditionsForPiece); }); @@ -73,10 +76,6 @@ let PieceListBulkModal = React.createClass({ EditionListActions.clearAllEditionSelections(); }, - handleSuccess(){ - - }, - render() { let availableAcls = this.getAvailableAcls(); let selectedEditions = this.fetchSelectedEditionList(); @@ -104,25 +103,25 @@ let PieceListBulkModal = React.createClass({ availableAcls={availableAcls} action="transfer" editions={selectedEditions} - currentUser={this.state.currentUser} + currentUser={this.state.user.currentUser} handleSuccess={this.handleSuccess} /> diff --git a/js/components/ascribe_table/table_item_wrapper.js b/js/components/ascribe_table/table_item_wrapper.js index a6ffa36b..62778174 100644 --- a/js/components/ascribe_table/table_item_wrapper.js +++ b/js/components/ascribe_table/table_item_wrapper.js @@ -21,7 +21,6 @@ let TableItemWrapper = React.createClass({ if(column.link) { let params = {}; params[column.link.paramsKey] = this.props.columnContent[column.link.contentKey]; - this.transitionTo(column.link.to, params); } }, diff --git a/js/components/edition_container.js b/js/components/edition_container.js index 6887fd20..7b8b6151 100644 --- a/js/components/edition_container.js +++ b/js/components/edition_container.js @@ -11,10 +11,11 @@ import Edition from './edition'; * This is the component that implements resource/data specific functionality */ let EditionContainer = React.createClass({ - getInitialState() { - return {'user': UserStore.getState(), - 'edition': EditionStore.getState()} + return { + 'user': UserStore.getState(), + 'edition': EditionStore.getState() + }; }, onChange(state) { @@ -22,10 +23,11 @@ let EditionContainer = React.createClass({ }, componentDidMount() { - EditionActions.fetchOne(this.props.params.editionId); EditionStore.listen(this.onChange); - UserActions.fetchCurrentUser(); UserStore.listen(this.onChange); + + UserActions.fetchCurrentUser(); + EditionActions.fetchOne(this.props.params.editionId); }, componentDidUnmount() { EditionStore.unlisten(this.onChange); @@ -33,18 +35,18 @@ let EditionContainer = React.createClass({ }, render() { - if('title' in this.state.edition) { return ( - + + ); } else { return (

Loading

); } - - } }); diff --git a/js/components/header.js b/js/components/header.js index b7a412e0..1c0116db 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -26,6 +26,10 @@ let Header = React.createClass({ UserActions.fetchCurrentUser(); }, + componentDidUnmount() { + UserStore.unlisten(this.onChange); + }, + onChange(state) { this.setState(state); }, diff --git a/js/components/piece_list.js b/js/components/piece_list.js index e6735a27..9d6ad26e 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -26,7 +26,7 @@ let PieceList = React.createClass({ PieceListActions.fetchPieceList(page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc); }, - componentWillUnmount() { + componentDidUnmount() { PieceListStore.unlisten(this.onChange); },