Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit108e753

Browse files
Update README.md
1 parent31c464d commit108e753

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

‎README.md‎

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,87 @@ React 的單向資料流架構模式
3939
}
4040
4141
42-
42+
43+
44+
// 2020, 7/13, pm 1:10 - 1: 35 (duration: 30 mins)
45+
// flux
46+
47+
var React = require("react");
48+
49+
50+
// UI Action -> Dispatcher
51+
52+
var App = React.createClass({
53+
54+
// Action
55+
AppAction: {
56+
57+
save: function(){},
58+
delete: function(id){},
59+
update: function(id){},
60+
get: function(res){}
61+
62+
},
63+
64+
// UI Action -> Dispatcher
65+
clickHandler: function(){
66+
67+
// onSave is a Dispather
68+
this.props.onSave(this.state.id);
69+
70+
},
71+
72+
render: function(){
73+
74+
return(
75+
76+
// onClick = {this.method} , this is bind html event to UI action to this class
77+
<div>
78+
<button onClick={this.clickHandler}>
79+
Save Info Now
80+
</button>
81+
</div>
82+
83+
);
84+
85+
}
86+
87+
});
88+
89+
90+
// View -> UI Action
91+
92+
var UIController = React.createClass({
93+
94+
render: function(){
95+
96+
var props = merge(
97+
98+
{}, this.state.app, {onSave = this.saveHandler};
99+
100+
);
101+
102+
return App(props);
103+
104+
}
105+
106+
});
107+
108+
// Dispatcher -> Store
109+
110+
Dispatcher.register(function(payload){
111+
112+
switch(payload.actionType){
113+
case AppConstants.Record: AppStore.save(payload.res);
114+
}
115+
116+
});
117+
118+
// Store -> Event -> View
119+
120+
AppStore.prototype.save = function(res){
121+
this.emitChange();
122+
}
43123
44124
45125

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp