-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.android.js
More file actions
66 lines (50 loc) · 1.29 KB
/
Copy pathindex.android.js
File metadata and controls
66 lines (50 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
* 官网demo-->https://github.com/mobxjs/mobx-react-boilerplate
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity
} from 'react-native';
import NewApp from './app';
// import AppState from './appState';
// const appState = new AppState();
import {observable,autorun,computed} from 'mobx';
var appState = observable({
timer : 0 ,
// get zijipao(){
// setInterval(()=>{
// this.timer += 1;
// },1000)
// }
zijipao : computed(function(){
setInterval(()=>{this.timer += 1;},1000)
})
})
import {action} from 'mobx';
appState.resetTimer = action(function reset() {
appState.timer = 0;
});
// setInterval(action(function tick() {
// appState.timer += 1;
// }), 1000);
autorun(function() {
// console.log("Completed %d of %d items",
appState.zijipao
// );
});
export default class Proj extends Component {
render() {
return (
<NewApp appState={appState}/>
);
}
}
AppRegistry.registerComponent('Proj', () => Proj);
//经验法则:如果你有一个函数应该自动运行,但不会产生一个新的值,请使用autorun。 其余情况都应该使用 computed。