0.1.8 • Published 7 years ago

mobx-viewbox v0.1.8

Weekly downloads
7
License
MIT
Repository
github
Last release
7 years ago

mobx-viewbox

基于mobx的react框架,jsfiddle demo

  • 自动绑定props值到component对象属性及方法(以_开头的属性和方法不会被覆盖),不需要从this.props取值再赋值到this.state
  • 属性赋值之后自动触发渲染,不再需要反复调用this.setState方法
  • 不需要关注react生命周期,默认init方法为初始化方法,首次渲染执行
  • 默认绑定component对象到dom元素,可利用dom选择器触发component方法,例如:this.querySelector('#todos').refresh()

Install

npm install mobx-viewbox --save

Usage

原始写法:

class Todo extends Component {
	
	constructor(props) {
		super(props)
		this.state.todo = props.todo || {
			title: '',
			finished: false
		}
	}
	
	checkboxChange() {
		let todo = {...this.state.todo}
		todo.finished = !todo.finished
		this.setState({todo})
	}

	render() {
		return <li>
	        <input
	            type="checkbox"
	            checked={this.todo.finished}
	            onChange={() => this.checkboxChange()}
	        />{this.todo.title}
	    </li>
	}
}

viewBox写法

class Todo extends ViewBox {
	todo = {
		title: '',
		finished: false
	}

	render() {
		return <li>
	        <input
	            type="checkbox"
	            checked={this.todo.finished}
	            onChange={() => this.todo.finished = !this.todo.finished}
	        />{this.todo.title}
	    </li>
	}
}

Demo

npm start
http://localhost:9090/demo/index.html
0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago