immutability
v1.0.2
Published
[](https://badge.fury.io/js/immutability) [](https://travis-ci.org/janryWang/immutability) [
class Tmall extends Component{
state = {
say:"Hello world",
rock:false
}
componnentDidMount(){
let self = this;
let {rock} = this.getState();
setInterval(()=>{
if(self.unmount) return;
self.setState({
say:rock ? 'Rock the world' : 'Hello world'
});
},1000);
}
componentWillUnmount(){
this.unmount = true;
}
render(){
return (
<div>{this.getState('say')}</div>
);
}
}学习成本非常低,只需要知道怎么使用
this.getState()这个API就行,记住,获取状态,不要再和过去一样this.state.say这样来获取哦,当然如果你想访问深层对象,this.getState('a.b.c.d[5]')这样就OK了。Immutable的API接口已集成到每个组件中,方便开发者使用,比如
this.toJS(),this.fromJS().....具体API文档请移步ImmutableJS文档
