actually what you were doing is right. the altContainer intentionally fires a redraw on its children when any change happens. that's its job.
so you need to use shouldComponentUpdate in your components to keep them from changing if the state changes for reasons it doesn't care about.
optimizing that can happen in 2 ways. 1) use multiple stores and multiple alt containers around different parts of your app, or 2) have a controller component that divides up the properties of the store into separate items that the real components need to know, so they don't necessarily rerender because their own properties might not be changed.
#!/home => home.js
myStore.fetchRabbits
. Sometimes, this results in an error that is "expected" (for example the user's access token has expired). These errors get handled fine by the error action I specified when I set up the async source. However, AltJS then rethrows the exception and my console.log fills up with unhandled exceptions.
myStore.fetchRabbits().catch(doNothing)
, where doNothing
is just a no-op function I wrote for the purpose. This means when the exception gets rethrown it gets caught here and silenced.
shouldFetch
support to my sources. If shouldFetch
returns false, the fetchRabbits
function doesn't return a promise, it just returns null. So I get a different set of exceptions filling up my log, complaining about calling catch
on a null object.
Thanks for the response. Okay, so the way in which you are meant to use async methods is something like this?
function inResponseToSomething() {
myStore.fetchRabbits().then(rabbits => myAction.update(rabbits)).catch(doNothing);
}
I have been instead specifying myAction.update
as the success
action in the async source. But that isn't the correct way to do things?
Hi, guys
I have a small trouble with parent and children components. So there is
Parent AltContainer -> DataLayout -> Inside DataLayout there are some another
AltContainer(s) - Big smart components.
After Parent AltContainer is cleared unlisten events in children components
don't fire.
someAction.defer()
instead of someAction()
.
componentDidMount() { MyStore.loadSomething(); }
loadSomething
dispatches a loading
action, e.g. via dataSource, to indicate busynesssuccess
hat caused the component to be mounted in the first place, and it being mounted is still part of the success
dispatch and while that hasn't finished, the system is trying to dispatch the next loading
actioncomponentDidMount() { setTimeout(() => MyStore.loadSomething()); }
SearchComponent
for searching your address then I have a MapComponent
for displaying a map. now I need to have my SearchComponent
allowing a user to put his/her address then click submit then the map location changes to the input address, and my SearchComponent
needs to have Googles AutoComplete fro places,SearchComponent
import React, { Component } from 'react'
import { MapContainer } from '../Map/MapContainer.jsx'
import Geosuggest from 'react-geosuggest'
export class SearchAddress extends Component {
constructor (props) {
super(props)
this.state = {
address: ''
}
this.handleSubmit = this.handleSubmit.bind(this)
}
handleSubmit(e) {
e.preventDefault()
console.log('value ',this.refs.srch.value)
}
onChange(){
}
render() {
return (
<div>
<form onSubmit={this.handleSubmit}>
<input size="35" ref="srch" type="search" id="search" placeholder="Search..." />
<button submit={this.handleSubmit} >Serach Address</button>
</form>
</div>
)
}
}
export function UnwrappedActions() {
if (!(this instanceof UnwrappedActions)) return new UnwrappedActions();
this.actionXXX = function(arg1, arg2) {
};
}
export default Alt.createActions(UnwrappedActions());