|
1 | | -/*global React ReactDOM __ Immutable __Component*/ |
| 1 | +/*global React ReactDOM __ Immutable __Element*/ |
2 | 2 |
|
3 | | -//const __Component = require("timeengine-react"); |
| 3 | +//const __Element = require("timeengine-react"); |
4 | 4 | //this code is required to transpile by `npm run jsx` |
5 | 5 |
|
6 | 6 | (() => { |
7 | 7 | 'use strict'; |
8 | 8 |
|
9 | | - const TextComponent = () => { |
| 9 | + const TextElement = () => { |
10 | 10 | const __value = __(); |
11 | 11 | const onChange = (e) => { |
12 | 12 | __value.t = e.target.value; |
|
19 | 19 | </div>)); |
20 | 20 |
|
21 | 21 | __value.t = "default text"; |
22 | | - return __Component(__seqEl); |
| 22 | + return __Element(__seqEl); |
23 | 23 | }; |
24 | 24 |
|
25 | 25 | // `.intervalSeq` is to map Immutable-js infinite Sequence |
26 | 26 | // on TimeEngine infinite Sequence |
27 | 27 | // map natural numbers sequence on intervalSeq(1000) |
28 | | - const TimerComponent = () => { |
29 | | - return __Component(__ |
| 28 | + const TimerElement = () => { |
| 29 | + return __Element(__ |
30 | 30 | .intervalSeq(Immutable.Range(), 1000) |
31 | 31 | .__((count) => (__.log.t = count)) //console.log |
32 | 32 | .__((count) => (<div>{"Timer : "}{count}</div>))); |
|
35 | 35 | // memory leak, performance issue |
36 | 36 | //how about games? memoized_reduce is needed |
37 | 37 | // to calculate many elemnents of the long array |
38 | | - const CounterComponentStateHistory = () => { |
| 38 | + const CounterElementStateHistory = () => { |
39 | 39 | const __updn = __(true); //1 or -1 or initially 0 |
40 | 40 | const __seqEl = __([__updn]) |
41 | 41 | .__(([updn]) => (__updn |
|
50 | 50 | onClick={() => (__updn.t = 1)}>{"Up"}</button> |
51 | 51 | <button |
52 | 52 | onClick={() => (__updn.t = -1)}>{"Down"}</button> |
53 | | - {__Component(__seqEl)} |
| 53 | + {__Element(__seqEl)} |
54 | 54 | </span>); |
55 | 55 | }; |
56 | 56 |
|
57 | 57 | // no seq object destroy |
58 | | - const CounterReloadComponent = () => { |
| 58 | + const CounterReloadElement = () => { |
59 | 59 | const __clicked = __(); |
60 | 60 | const onClick = () => { |
61 | 61 | __clicked.t = true; |
|
64 | 64 | .intervalSeq(Immutable.Seq.of(true), 0) |
65 | 65 | .__(onClick); |
66 | 66 | const __seqEl = __([__clicked]) |
67 | | - .__(() => (<span>{CounterComponentStateHistory()}</span>)); |
| 67 | + .__(() => (<span>{CounterElementStateHistory()}</span>)); |
68 | 68 | return (<div> |
69 | | - {__Component(__seqEl)} |
| 69 | + {__Element(__seqEl)} |
70 | 70 | <button onClick={onClick}>{"Reload"}</button> |
71 | 71 | </div>); |
72 | 72 | }; |
73 | 73 |
|
74 | | - const CounterComponent = () => { |
| 74 | + const CounterElement = () => { |
75 | 75 | const __updn = __(); |
76 | 76 | const __count = __([__updn]) |
77 | 77 | .__(([updn]) => ((updn === 0) ? (0) : (__count.t + updn))); |
|
86 | 86 | onClick={() => (__updn.t = 1)}>{"Up"}</button> |
87 | 87 | <button |
88 | 88 | onClick={() => (__updn.t = -1)}>{"Down"}</button> |
89 | | - {__Component(__seqEl)} |
| 89 | + {__Element(__seqEl)} |
90 | 90 | <button |
91 | 91 | onClick={init}>{"Reset"}</button> |
92 | 92 | </div>); |
93 | 93 | }; |
94 | 94 |
|
95 | 95 |
|
96 | 96 |
|
97 | | - const PhysicsComponent = () => { |
| 97 | + const PhysicsElement = () => { |
98 | 98 | //MKS system of units |
99 | 99 | const V0 = 85.0; // m/s |
100 | 100 | const DEG = 40; //degree |
|
116 | 116 | cx = {50 + x * Drawscale} cy = {250 - y * Drawscale}/> |
117 | 117 | </svg> |
118 | 118 | </div>)); |
119 | | - return __Component(__seqEl); |
| 119 | + return __Element(__seqEl); |
120 | 120 | }; |
121 | 121 |
|
122 | | - const ButtonComponent = () => { |
| 122 | + const ButtonElement = () => { |
123 | 123 | const __clicked = __(); |
124 | 124 | const onClick = () => { |
125 | 125 | __clicked.t = true; |
126 | 126 | }; |
127 | 127 | const __seqEl = __([__clicked]) |
128 | | - .__(() => (<div>{PhysicsComponent()}</div>)); |
| 128 | + .__(() => (<div>{PhysicsElement()}</div>)); |
129 | 129 |
|
130 | 130 | return (<div> |
131 | 131 | <div><button onClick={onClick}>{"Physics Start"}</button></div> |
132 | | - {__Component(__seqEl)} |
| 132 | + {__Element(__seqEl)} |
133 | 133 | </div> |
134 | 134 | ); |
135 | 135 | }; |
136 | 136 |
|
137 | 137 | const TopElement = ( |
138 | 138 | <div> |
139 | 139 | <p>{"HelloElement!!"}</p> |
140 | | - {TextComponent()} |
| 140 | + {TextElement()} |
141 | 141 | {"====================="} |
142 | | - {TimerComponent()} |
| 142 | + {TimerElement()} |
143 | 143 | {"====================="} |
144 | | - <div>{CounterComponentStateHistory()}</div> |
| 144 | + <div>{CounterElementStateHistory()}</div> |
145 | 145 | {"====================="} |
146 | | - {CounterReloadComponent()} |
| 146 | + {CounterReloadElement()} |
147 | 147 | {"====================="} |
148 | | - {CounterComponent()} |
| 148 | + {CounterElement()} |
149 | 149 | {"====================="} |
150 | | - {ButtonComponent()} |
| 150 | + {ButtonElement()} |
151 | 151 | {"====================="} |
152 | 152 | </div> |
153 | 153 | ); |
|
0 commit comments