Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 45 additions & 17 deletions src/FixedDataTableContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,7 @@ class FixedDataTableContainer extends React.Component {
constructor(props) {
super(props);

this.reduxStore = FixedDataTableStore.get();

this.scrollActions = getScrollActions(this.reduxStore, () => this.props);

this.reduxStore.dispatch(initialize(props));

this.unsubscribe = this.reduxStore.subscribe(this.onStoreUpdate.bind(this));
this.state = {
boundState: FixedDataTableContainer.getBoundState(this.reduxStore), // the state from the redux store
reduxStore: this.reduxStore, // put store instance in local state so that getDerivedStateFromProps can access it
props, // put props in local state so that getDerivedStateFromProps can access it
};
this._initialize(props);

this.fixedDataTableApi = createApi();
this.previousApiValue = null;
Expand Down Expand Up @@ -83,18 +72,57 @@ class FixedDataTableContainer extends React.Component {
};
}

componentDidMount() {
this._initialize(this.props);
}

componentWillUnmount() {
if (this.unsubscribe) {
this.unsubscribe();
this.unsubscribe = null;
}
this.reduxStore = null;
this._cleanup();
}

componentDidUpdate() {
this.notifyApiValueChanges();
}

_initialize(props) {
if (this.reduxStore) {
// already initialized
return;
}

this.reduxStore = FixedDataTableStore.get();
this.reduxStore.dispatch(initialize(props));

this.scrollActions = getScrollActions(this.reduxStore, () => this.props);

this.unsubscribe = this.reduxStore.subscribe(this.onStoreUpdate.bind(this));

const state = {
boundState: FixedDataTableContainer.getBoundState(this.reduxStore), // the state from the redux store
reduxStore: this.reduxStore, // put store instance in local state so that getDerivedStateFromProps can access it
props, // put props in local state so that getDerivedStateFromProps can access it
};

if (this.state) {
// component is already constructed, so just update state
this.setState(state);
} else {
// component isn't constructed yet, so initialize state
this.state = state;
}
}

_cleanup() {
if (!this.reduxStore) {
// already cleaned up
return;
}

this.unsubscribe();
this.unsubscribe = null;
this.reduxStore = null;
}

/**
* Returns FDT's public API.
*
Expand Down
Loading