ripple 0.2.87 → 0.2.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/compiler/phases/1-parse/index.js +74 -7
- package/src/compiler/phases/2-analyze/index.js +3 -1
- package/src/compiler/phases/3-transform/client/index.js +52 -17
- package/src/runtime/array.js +9 -242
- package/src/runtime/index-client.js +3 -1
- package/src/runtime/internal/client/constants.js +2 -0
- package/src/runtime/internal/client/for.js +403 -403
- package/src/runtime/internal/client/if.js +29 -29
- package/src/runtime/internal/client/index.js +4 -0
- package/src/runtime/internal/client/operations.js +0 -1
- package/src/runtime/internal/client/render.js +5 -5
- package/src/runtime/internal/client/runtime.js +2 -2
- package/src/runtime/internal/client/script.js +16 -0
- package/src/runtime/internal/client/utils.js +4 -0
- package/src/runtime/internal/server/index.js +5 -2
- package/src/runtime/object.js +29 -0
- package/src/runtime/proxy.js +341 -0
- package/src/utils/events.js +3 -3
- package/tests/client/__snapshots__/basic.test.ripple.snap +13 -0
- package/tests/client/array.test.ripple +3 -3
- package/tests/client/basic.test.ripple +90 -0
- package/tests/client/head.test.ripple +196 -0
- package/tests/client/object.test.ripple +183 -0
- package/types/index.d.ts +8 -0
|
@@ -17,29 +17,29 @@ import { array_from, is_array } from './utils.js';
|
|
|
17
17
|
* @returns {Block}
|
|
18
18
|
*/
|
|
19
19
|
function create_item(anchor, value, index, render_fn, is_indexed) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
var b = branch(() => {
|
|
21
|
+
var tracked_index;
|
|
22
|
+
|
|
23
|
+
if (is_indexed) {
|
|
24
|
+
var block = /** @type {Block} */ (active_block);
|
|
25
|
+
|
|
26
|
+
if (block.s === null) {
|
|
27
|
+
tracked_index = tracked(index, block);
|
|
28
|
+
|
|
29
|
+
block.s = {
|
|
30
|
+
start: null,
|
|
31
|
+
end: null,
|
|
32
|
+
i: tracked_index,
|
|
33
|
+
};
|
|
34
|
+
} else {
|
|
35
|
+
tracked_index = block.s.i;
|
|
36
|
+
}
|
|
37
|
+
render_fn(anchor, value, tracked_index);
|
|
38
|
+
} else {
|
|
39
|
+
render_fn(anchor, value);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return b;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
@@ -48,22 +48,22 @@ function create_item(anchor, value, index, render_fn, is_indexed) {
|
|
|
48
48
|
* @returns {void}
|
|
49
49
|
*/
|
|
50
50
|
function move(block, anchor) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
var node = block.s.start;
|
|
52
|
+
var end = block.s.end;
|
|
53
|
+
|
|
54
|
+
if (node === end) {
|
|
55
|
+
anchor.before(node);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
while (node !== null) {
|
|
59
|
+
var next_node = /** @type {Node} */ (next_sibling(node));
|
|
60
|
+
anchor.before(node);
|
|
61
|
+
node = next_node;
|
|
62
|
+
if (node === end) {
|
|
63
|
+
anchor.before(end);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
@@ -72,15 +72,15 @@ function move(block, anchor) {
|
|
|
72
72
|
* @returns {V[]}
|
|
73
73
|
*/
|
|
74
74
|
function collection_to_array(collection) {
|
|
75
|
-
|
|
75
|
+
var array = is_array(collection) ? collection : collection == null ? [] : array_from(collection);
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
// If we are working with a tracked array, then we need to get a copy of
|
|
78
|
+
// the elements, as the array itself is proxied, and not useful in diffing
|
|
79
|
+
if (TRACKED_ARRAY in array) {
|
|
80
|
+
array = array_from(array);
|
|
81
|
+
}
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
return array;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
@@ -92,23 +92,23 @@ function collection_to_array(collection) {
|
|
|
92
92
|
* @returns {void}
|
|
93
93
|
*/
|
|
94
94
|
export function for_block(node, get_collection, render_fn, flags) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
95
|
+
var is_controlled = (flags & IS_CONTROLLED) !== 0;
|
|
96
|
+
var is_indexed = (flags & IS_INDEXED) !== 0;
|
|
97
|
+
var anchor = /** @type {Element | Text} */ (node);
|
|
98
|
+
|
|
99
|
+
if (is_controlled) {
|
|
100
|
+
anchor = node.appendChild(create_text());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
render(() => {
|
|
104
|
+
var block = /** @type {Block} */ (active_block);
|
|
105
|
+
var collection = get_collection();
|
|
106
|
+
var array = collection_to_array(collection);
|
|
107
|
+
|
|
108
|
+
untrack(() => {
|
|
109
|
+
reconcile(anchor, block, array, render_fn, is_controlled, is_indexed);
|
|
110
|
+
});
|
|
111
|
+
}, FOR_BLOCK);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
@@ -119,13 +119,13 @@ export function for_block(node, get_collection, render_fn, flags) {
|
|
|
119
119
|
* @returns {void}
|
|
120
120
|
*/
|
|
121
121
|
function reconcile_fast_clear(anchor, block, array) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
var state = block.s;
|
|
123
|
+
var parent_node = /** @type {Element} */ (anchor.parentNode);
|
|
124
|
+
parent_node.textContent = '';
|
|
125
|
+
destroy_block_children(block);
|
|
126
|
+
parent_node.append(anchor);
|
|
127
|
+
state.array = array;
|
|
128
|
+
state.blocks = [];
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
@@ -134,7 +134,7 @@ function reconcile_fast_clear(anchor, block, array) {
|
|
|
134
134
|
* @returns {void}
|
|
135
135
|
*/
|
|
136
136
|
function update_index(block, index) {
|
|
137
|
-
|
|
137
|
+
set(block.s.i, index, block);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/**
|
|
@@ -148,248 +148,248 @@ function update_index(block, index) {
|
|
|
148
148
|
* @returns {void}
|
|
149
149
|
*/
|
|
150
150
|
function reconcile(anchor, block, b, render_fn, is_controlled, is_indexed) {
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
151
|
+
var state = block.s;
|
|
152
|
+
|
|
153
|
+
// Variables used in conditional branches - declare with initial values
|
|
154
|
+
/** @type {number} */
|
|
155
|
+
var a_start = 0;
|
|
156
|
+
/** @type {number} */
|
|
157
|
+
var b_start = 0;
|
|
158
|
+
/** @type {number} */
|
|
159
|
+
var a_left = 0;
|
|
160
|
+
/** @type {number} */
|
|
161
|
+
var b_left = 0;
|
|
162
|
+
/** @type {Int32Array} */
|
|
163
|
+
var sources = new Int32Array(0);
|
|
164
|
+
/** @type {boolean} */
|
|
165
|
+
var moved = false;
|
|
166
|
+
/** @type {number} */
|
|
167
|
+
var pos = 0;
|
|
168
|
+
/** @type {number} */
|
|
169
|
+
var patched = 0;
|
|
170
|
+
/** @type {number} */
|
|
171
|
+
var i = 0;
|
|
172
|
+
|
|
173
|
+
if (state === null) {
|
|
174
|
+
state = block.s = {
|
|
175
|
+
array: [],
|
|
176
|
+
blocks: [],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
var a = state.array;
|
|
181
|
+
var a_length = a.length;
|
|
182
|
+
var b_length = b.length;
|
|
183
|
+
var j = 0;
|
|
184
|
+
|
|
185
|
+
// Fast-path for clear
|
|
186
|
+
if (is_controlled && b_length === 0) {
|
|
187
|
+
if (a_length > 0) {
|
|
188
|
+
reconcile_fast_clear(anchor, block, b);
|
|
189
|
+
}
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
var b_blocks = Array(b_length);
|
|
193
|
+
|
|
194
|
+
// Fast-path for create
|
|
195
|
+
if (a_length === 0) {
|
|
196
|
+
for (; j < b_length; j++) {
|
|
197
|
+
b_blocks[j] = create_item(anchor, b[j], j, render_fn, is_indexed);
|
|
198
|
+
}
|
|
199
|
+
state.array = b;
|
|
200
|
+
state.blocks = b_blocks;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
var a_blocks = state.blocks;
|
|
205
|
+
var a_val = a[j];
|
|
206
|
+
var b_val = b[j];
|
|
207
|
+
var a_end = a_length - 1;
|
|
208
|
+
var b_end = b_length - 1;
|
|
209
|
+
var b_block;
|
|
210
|
+
|
|
211
|
+
outer: {
|
|
212
|
+
while (a_val === b_val) {
|
|
213
|
+
a[j] = b_val;
|
|
214
|
+
b_block = b_blocks[j] = a_blocks[j];
|
|
215
|
+
if (is_indexed) {
|
|
216
|
+
update_index(b_block, j);
|
|
217
|
+
}
|
|
218
|
+
++j;
|
|
219
|
+
if (j > a_end || j > b_end) {
|
|
220
|
+
break outer;
|
|
221
|
+
}
|
|
222
|
+
a_val = a[j];
|
|
223
|
+
b_val = b[j];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
a_val = a[a_end];
|
|
227
|
+
b_val = b[b_end];
|
|
228
|
+
|
|
229
|
+
while (a_val === b_val) {
|
|
230
|
+
a[a_end] = b_val;
|
|
231
|
+
b_block = b_blocks[b_end] = a_blocks[a_end];
|
|
232
|
+
if (is_indexed) {
|
|
233
|
+
update_index(b_block, b_end);
|
|
234
|
+
}
|
|
235
|
+
a_end--;
|
|
236
|
+
b_end--;
|
|
237
|
+
if (j > a_end || j > b_end) {
|
|
238
|
+
break outer;
|
|
239
|
+
}
|
|
240
|
+
a_val = a[a_end];
|
|
241
|
+
b_val = b[b_end];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
var fast_path_removal = false;
|
|
246
|
+
|
|
247
|
+
if (j > a_end) {
|
|
248
|
+
if (j <= b_end) {
|
|
249
|
+
while (j <= b_end) {
|
|
250
|
+
b_val = b[j];
|
|
251
|
+
var target = j >= a_length ? anchor : a_blocks[j].s.start;
|
|
252
|
+
b_blocks[j] = create_item(target, b_val, j, render_fn, is_indexed);
|
|
253
|
+
j++;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
} else if (j > b_end) {
|
|
257
|
+
while (j <= a_end) {
|
|
258
|
+
destroy_block(a_blocks[j++]);
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
a_start = j;
|
|
262
|
+
b_start = j;
|
|
263
|
+
a_left = a_end - j + 1;
|
|
264
|
+
b_left = b_end - j + 1;
|
|
265
|
+
sources = new Int32Array(b_left + 1);
|
|
266
|
+
moved = false;
|
|
267
|
+
pos = 0;
|
|
268
|
+
patched = 0;
|
|
269
|
+
i = 0;
|
|
270
|
+
|
|
271
|
+
fast_path_removal = is_controlled && a_left === a_length;
|
|
272
|
+
|
|
273
|
+
// When sizes are small, just loop them through
|
|
274
|
+
if (b_length < 4 || (a_left | b_left) < 32) {
|
|
275
|
+
for (i = a_start; i <= a_end; ++i) {
|
|
276
|
+
a_val = a[i];
|
|
277
|
+
if (patched < b_left) {
|
|
278
|
+
for (j = b_start; j <= b_end; j++) {
|
|
279
|
+
b_val = b[j];
|
|
280
|
+
if (a_val === b_val) {
|
|
281
|
+
sources[j - b_start] = i + 1;
|
|
282
|
+
if (fast_path_removal) {
|
|
283
|
+
fast_path_removal = false;
|
|
284
|
+
while (a_start < i) {
|
|
285
|
+
destroy_block(a_blocks[a_start++]);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (pos > j) {
|
|
289
|
+
moved = true;
|
|
290
|
+
} else {
|
|
291
|
+
pos = j;
|
|
292
|
+
}
|
|
293
|
+
b_block = b_blocks[j] = a_blocks[i];
|
|
294
|
+
if (is_indexed) {
|
|
295
|
+
update_index(b_block, j);
|
|
296
|
+
}
|
|
297
|
+
++patched;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (!fast_path_removal && j > b_end) {
|
|
302
|
+
destroy_block(a_blocks[i]);
|
|
303
|
+
}
|
|
304
|
+
} else if (!fast_path_removal) {
|
|
305
|
+
destroy_block(a_blocks[i]);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
var map = new Map();
|
|
310
|
+
|
|
311
|
+
for (i = b_start; i <= b_end; ++i) {
|
|
312
|
+
map.set(b[i], i);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
for (i = a_start; i <= a_end; ++i) {
|
|
316
|
+
a_val = a[i];
|
|
317
|
+
|
|
318
|
+
if (patched < b_left) {
|
|
319
|
+
j = map.get(a_val);
|
|
320
|
+
|
|
321
|
+
if (j !== undefined) {
|
|
322
|
+
if (fast_path_removal) {
|
|
323
|
+
fast_path_removal = false;
|
|
324
|
+
// while (i > a_start) {
|
|
325
|
+
// destroy_block(a[a_start++]);
|
|
326
|
+
// }
|
|
327
|
+
}
|
|
328
|
+
sources[j - b_start] = i + 1;
|
|
329
|
+
if (pos > j) {
|
|
330
|
+
moved = true;
|
|
331
|
+
} else {
|
|
332
|
+
pos = j;
|
|
333
|
+
}
|
|
334
|
+
b_val = b[j];
|
|
335
|
+
block = b_blocks[j] = a_blocks[i];
|
|
336
|
+
if (is_indexed) {
|
|
337
|
+
update_index(block, j);
|
|
338
|
+
}
|
|
339
|
+
++patched;
|
|
340
|
+
} else if (!fast_path_removal) {
|
|
341
|
+
destroy_block(a_blocks[i]);
|
|
342
|
+
}
|
|
343
|
+
} else if (!fast_path_removal) {
|
|
344
|
+
destroy_block(a_blocks[i]);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (fast_path_removal) {
|
|
351
|
+
reconcile_fast_clear(anchor, block, []);
|
|
352
|
+
reconcile(anchor, block, b, render_fn, is_controlled, is_indexed);
|
|
353
|
+
return;
|
|
354
|
+
} else if (moved) {
|
|
355
|
+
var next_pos = 0;
|
|
356
|
+
var seq = lis_algorithm(sources);
|
|
357
|
+
j = seq.length - 1;
|
|
358
|
+
|
|
359
|
+
for (i = b_left - 1; i >= 0; i--) {
|
|
360
|
+
if (sources[i] === 0) {
|
|
361
|
+
pos = i + b_start;
|
|
362
|
+
b_val = b[pos];
|
|
363
|
+
next_pos = pos + 1;
|
|
364
|
+
|
|
365
|
+
var target = next_pos < b_length ? b_blocks[next_pos].s.start : anchor;
|
|
366
|
+
b_blocks[pos] = create_item(target, b_val, pos, render_fn, is_indexed);
|
|
367
|
+
} else if (j < 0 || i !== seq[j]) {
|
|
368
|
+
pos = i + b_start;
|
|
369
|
+
b_val = b[pos];
|
|
370
|
+
next_pos = pos + 1;
|
|
371
|
+
|
|
372
|
+
var target = next_pos < b_length ? b_blocks[next_pos].s.start : anchor;
|
|
373
|
+
move(b_blocks[pos], target);
|
|
374
|
+
} else {
|
|
375
|
+
j--;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
} else if (patched !== b_left) {
|
|
379
|
+
for (i = b_left - 1; i >= 0; i--) {
|
|
380
|
+
if (sources[i] === 0) {
|
|
381
|
+
pos = i + b_start;
|
|
382
|
+
b_val = b[pos];
|
|
383
|
+
next_pos = pos + 1;
|
|
384
|
+
|
|
385
|
+
var target = next_pos < b_length ? b_blocks[next_pos].s.start : anchor;
|
|
386
|
+
b_blocks[pos] = create_item(target, b_val, pos, render_fn, is_indexed);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
state.array = b;
|
|
392
|
+
state.blocks = b_blocks;
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
/** @type {Int32Array} */
|
|
@@ -403,64 +403,64 @@ let maxLen = 0;
|
|
|
403
403
|
* @returns {Int32Array}
|
|
404
404
|
*/
|
|
405
405
|
function lis_algorithm(arr) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
406
|
+
let arrI = 0;
|
|
407
|
+
let i = 0;
|
|
408
|
+
let j = 0;
|
|
409
|
+
let k = 0;
|
|
410
|
+
let u = 0;
|
|
411
|
+
let v = 0;
|
|
412
|
+
let c = 0;
|
|
413
|
+
var len = arr.length;
|
|
414
|
+
|
|
415
|
+
if (len > maxLen) {
|
|
416
|
+
maxLen = len;
|
|
417
|
+
result = new Int32Array(len);
|
|
418
|
+
p = new Int32Array(len);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
for (; i < len; ++i) {
|
|
422
|
+
arrI = arr[i];
|
|
423
|
+
|
|
424
|
+
if (arrI !== 0) {
|
|
425
|
+
j = result[k];
|
|
426
|
+
if (arr[j] < arrI) {
|
|
427
|
+
p[i] = j;
|
|
428
|
+
result[++k] = i;
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
u = 0;
|
|
433
|
+
v = k;
|
|
434
|
+
|
|
435
|
+
while (u < v) {
|
|
436
|
+
c = (u + v) >> 1;
|
|
437
|
+
if (arr[result[c]] < arrI) {
|
|
438
|
+
u = c + 1;
|
|
439
|
+
} else {
|
|
440
|
+
v = c;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (arrI < arr[result[u]]) {
|
|
445
|
+
if (u > 0) {
|
|
446
|
+
p[i] = result[u - 1];
|
|
447
|
+
}
|
|
448
|
+
result[u] = i;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
u = k + 1;
|
|
454
|
+
var seq = new Int32Array(u);
|
|
455
|
+
v = result[u - 1];
|
|
456
|
+
|
|
457
|
+
while (u-- > 0) {
|
|
458
|
+
seq[u] = v;
|
|
459
|
+
v = p[v];
|
|
460
|
+
result[u] = 0;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return seq;
|
|
464
464
|
}
|
|
465
465
|
|
|
466
466
|
/**
|
|
@@ -471,46 +471,46 @@ function lis_algorithm(arr) {
|
|
|
471
471
|
* @returns {V[]}
|
|
472
472
|
*/
|
|
473
473
|
export function keyed(collection, key_fn) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
474
|
+
var block = active_block;
|
|
475
|
+
if (block === null || (block.f & FOR_BLOCK) === 0) {
|
|
476
|
+
throw new Error('keyed() must be used inside a for block');
|
|
477
|
+
}
|
|
478
478
|
|
|
479
|
-
|
|
480
|
-
|
|
479
|
+
var b_array = collection_to_array(collection);
|
|
480
|
+
var b_keys = b_array.map(key_fn);
|
|
481
481
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
482
|
+
// We only need to do this in DEV
|
|
483
|
+
var b = new Set(b_keys);
|
|
484
|
+
if (b.size !== b_keys.length) {
|
|
485
|
+
throw new Error('Duplicate keys are not allowed');
|
|
486
|
+
}
|
|
487
487
|
|
|
488
|
-
|
|
488
|
+
var state = block.s;
|
|
489
489
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
490
|
+
if (state === null) {
|
|
491
|
+
return b_array;
|
|
492
|
+
}
|
|
493
493
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
494
|
+
var a_array = state.array;
|
|
495
|
+
var a_keys = a_array.map(key_fn);
|
|
496
|
+
var a = new Map();
|
|
497
497
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
498
|
+
for (let i = 0; i < a_keys.length; i++) {
|
|
499
|
+
a.set(a_keys[i], i);
|
|
500
|
+
}
|
|
501
501
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
502
|
+
if (a.size !== a_keys.length) {
|
|
503
|
+
throw new Error('Duplicate keys are not allowed');
|
|
504
|
+
}
|
|
505
505
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
506
|
+
for (let i = 0; i < b_keys.length; i++) {
|
|
507
|
+
var b_val = b_keys[i];
|
|
508
|
+
var index = a.get(b_val);
|
|
509
509
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
510
|
+
if (index !== undefined) {
|
|
511
|
+
b_array[i] = a_array[index];
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
514
|
|
|
515
|
-
|
|
515
|
+
return b_array;
|
|
516
516
|
}
|