main
ts 41 lines 1.06 KB
Raw
1 import {identity, mutate} from 'shared-runtime';
2
3 /**
4 * Currently, InferReactiveScopeVariables do not ensure that maybe-aliased
5 * values get assigned the same reactive scope. This is safe only when an
6 * already-constructed value is captured, e.g.
7 * ```js
8 * const x = makeObj(); ⌝ mutable range of x
9 * mutate(x); ⌟
10 * <-- after this point, we can produce a canonical version
11 * of x for all following aliases
12 * const y = [];
13 * y.push(x); <-- y captures x
14 * ```
15 *
16 * However, if a value is captured/aliased during its mutable range and the
17 * capturing container is separately memoized, it becomes difficult to guarantee
18 * that all aliases refer to the same value.
19 *
20 */
21 function useFoo({a, b}) {
22 const x = {a};
23 const y = {};
24 mutate(x);
25 const z = [identity(y), b];
26 mutate(y);
27
28 if (z[0] !== y) {
29 throw new Error('oh no!');
30 }
31 return z;
32 }
33
34 export const FIXTURE_ENTRYPOINT = {
35 fn: useFoo,
36 params: [{a: 2, b: 3}],
37 sequentialRenders: [
38 {a: 2, b: 3},
39 {a: 4, b: 3},
40 ],
41 };