forked from lelandrichardson/knockout-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
75 lines (59 loc) · 1.58 KB
/
test.html
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
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>knockout react test</title>
</head>
<body>
<h3>Knockout Example</h3>
<div id="koTest">
<div data-bind="text: text"></div>
<div data-bind="react: { $: ToDoList, props: { todos: todos }}"></div>
</div>
<h3>React Example</h3>
<div id="reactTest"></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/react/0.13.1/react.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-min.js"></script>
<script src="index.js"></script>
<script>
var ToDoList = React.createClass({
mixins: [KnockoutMixin],
propTypes: {
todos: React.PropTypes.array.isRequired
},
render() {
return ( < ul data - bind = "foreach: props.todos" >
< li data - bind = "text: $data" > < /li> < /ul >
);
}
});
var vm = {
text: "some text",
todos: ko.observableArray([
"one", "two", "three"
])
};
ko.applyBindings(vm, document.getElementById("koTest"));
setInterval(function() {
vm.todos.shift();
vm.todos.push("" + Math.random());
}, 100);
// react example
var reactList = ["one", "two", "three"];
var render = function(todos) {
React.render(
React.createElement(ToDoList, {
todos: todos
}),
document.getElementById("reactTest")
);
};
render(reactList);
setInterval(function() {
reactList.shift();
reactList.push("" + Math.random());
render(reactList);
}, 100);
</script>
</body>
</html>