In each of the React components (readingList
and bookList
), getInitialState()
is initialized with the store public method getReadingList()
and getLibrary()
, respectively.
Various methods are executed at precise points in a component's lifecycle.
componentWillMount()
is a React lifecycle method. It is invoked once, both on the client and server, immediately before the initial rendering occurs. If you callsetState
within this method,render()
will see the updated state and will be executed only once despite change in the state:componentWillMount:function(){ AppStore.addChangeListener(this._onChange) }, _onChange: function(){ this.setState(readingItems()) }
Thus,
componentWillMount()
is listening to theaddChangeListener
(defined in theAppStore
store). If the_onChange
parameter is passed, then the current object (_this
) is updated (setState
) with the new/updated data/payload (readingItems
).In order to remove the items from the reading list, the event listener...