-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventsPlan.js
214 lines (163 loc) · 3.57 KB
/
EventsPlan.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// ignore period nodes, just filler to keep structure
var eventTree = {
__func: func, // Event -> Event
__offset: offset, // From the nearest MAP node parent / "domainating". Reset offset only for descendents of MAP nodes.
__kid1: null, // Only MAP nodes have kids. Direct MAP descendents ignoring the filler nodes and event nodes.
__kidN: null,
__leaf1: null, // Direct event node descendents ignoring fillers. Only MAP nodes will have them.
__leafN: null,
__newKid1: null, // All non-filler local descendents of MAP node.
__newKid2: null,
__parent: null, // The direct MAP node parent. Everyone except ROOT.
__next: null // The next MAP node. Linked list of siblings.
}
type alias AtEventNode =
{ index: Int
, listeners: List ListenerEventNode
, maps: List MapEventNode
, parent: EventNode
}
type alias MapEventNode =
{ func: Event -> Event
, parent: EventNode
}
type alias ListenerEventNode =
{ listeners: Dict String (Event -> Event)
, parent: EventNode
}
type EventNode
= EventAt AtEventNode
| MapEvent MapEventNode
| Listener ListenerEventNode
var mapNode = {
__func: func,
__parent: null,
__next: null,
__headChild: null,
__tailChild: null
}
{
funcs: [eventName: eventHandler], // [String: Event -> Event]
offset: Int,
parent: null,
next: null // Perhaps another leaf
}
kid1 -> null
kidN ->
offsetDelta += oldMap.eventDescendentCount
leaf1 -> {2+1} -> {2+offsetDelta} -> null
leafN ->
. o .
\ | /
. o .
\ | /
MAP MAP
| /
. MAP
\ /
.
|
ROOT
MAP can have only one direct child
1 2 3
\ | /
0 4 5
\ | /
3 0
| /
2 4
\ /
1
|
0
. o .
\ | /
. o .
\ | /
.
|
MAP
|
ROOT
2 3 4
\ | /
1 5 6
\ | /
0
|
1
|
0
ROOT = {
func: ...,
offset: 0,
handlerListHd: undefined,
handlerListTl: undefined,
parent: undefined,
next: undefined,
kidListHd: MAP,
kidListTl: MAP
}
MAP = {
func: ...,
offset: 1,
handlerListHd: o(3),
handlerListTl: o(5),
parent: ROOT,
next: undefined,
kidListHd: undefined,
kidListTl: undefined
}
o(3) = {
__funcs: ...,
__offset: 3,
__parent: MAP,
__next: o(5)
}
o(5) = {
__funcs: ...,
__offset: 5,
__parent: MAP,
__next: undefined
}
o(3) -> o(5)
| /
| /
MAP(1)
|
ROOT(0)
// In Swift, Event -> ()
// JS function exposed in Swift
function onTouch(event)
{
var realFunc = onTouch.__pointer_into_event_tree
realFunc(event)
}
onTouch.__pointer_into_event_tree = eventLeaf
createEventHandler
function onTouch(event)
{
var leaf = onTouch.__pointer_into_event_tree
event = leaf['touch'](event)
while (leaf.__parent)
{
leaf = leaf.__parent;
event = leaf.__func(event);
}
}
onTouch.__pointer_into_event_tree = leaf;
Sorry to bother you. I’ve been working on the events problem today and a thought occurred to me. Could we model the event tree in a similar way to the new patch tree. Each `At` node can store the index of the corresponding UIKit node in its parent’s children array, a pointer to its parent in the event tree,
case __2_TAGGER:
while (x.__child.$ === __2_TAGGER) {
x = x.__child;
}
y.__parent = eventNode;
while (y.__child.$ === __2_TAGGER) {
y.__child.__parent = y;
y = y.__child;
}
x.__func = y.__func;
x.__child = y.__child;
x.__parent = y.__parent;
diffHelp(x.__child, y.__child, y, ...);
return;